{"id":4811,"date":"2022-05-11T13:43:25","date_gmt":"2022-05-11T11:43:25","guid":{"rendered":"https:\/\/www.msb365.blog\/?p=4811"},"modified":"2024-03-26T15:47:42","modified_gmt":"2024-03-26T13:47:42","slug":"clean-microsoft-teams-cache","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=4811","title":{"rendered":"Clear Microsoft Teams cache using PowerShell &#8211; Intune compatible"},"content":{"rendered":"<p>In this blog article I describe the functionality (documentation) of my latest script for Microsoft Teams.<\/p>\n<p>It is about deleting the Teams cache for one or more users.<br \/>\nThis can be done in different ways.<br \/>\nOn the one hand, there is a really great tool by Johannes Huber under the following link:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"e5FkzeCcBJ\"><p><a href=\"https:\/\/www.itnator.net\/teams-cache-loeschen-per-tool-cleaner\/\">Teams Cache l\u00f6schen per Tool (Teams Cache Cleaner)<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8222;Teams Cache l\u00f6schen per Tool (Teams Cache Cleaner)&#8220; &#8212; www.itnator.net\" src=\"https:\/\/www.itnator.net\/teams-cache-loeschen-per-tool-cleaner\/embed\/#?secret=m8MjVifqWs#?secret=e5FkzeCcBJ\" data-secret=\"e5FkzeCcBJ\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>The problem here, however, is that this tool must be run on each affected device.<\/p>\n<p>In principle, this is much easier. We can execute a small BAT file which also deletes the team cache.<\/p>\n<p>However, it becomes more difficult with the following points:<\/p>\n<p>How can I distribute this BAT file to the user computers that are affected? How can I ensure that the BAT file is only executed once? How can the script be executed so that the user does not have to interact? Finally, how can we ensure logging?<\/p>\n<p>&nbsp;<\/p>\n<p>I have addressed these questions and written a PowerShell script that solves all these problems.<\/p>\n<p>The script is written in such a way that we can distribute it via Microsoft Intune.<\/p>\n<p>&nbsp;<\/p>\n<h3>Functionality:<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/100.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4814\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/100.png\" alt=\"\" width=\"464\" height=\"161\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/100.png 464w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/100-300x104.png 300w\" sizes=\"(max-width: 464px) 100vw, 464px\" \/><\/a><\/td>\n<td width=\"301\">If the script is executed for the first time, it will be checked whether the directory C:\\MDM\\Logging exists. If this is not the case, the directory is created accordingly.<\/p>\n<p>This directory serves as data storage for the created log file.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/101.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4815\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/101.png\" alt=\"\" width=\"511\" height=\"20\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/101.png 511w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/101-300x12.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/101-500x20.png 500w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><\/td>\n<td width=\"301\">The next step is to start PowerShell Transcripting.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/102.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4816\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/102.png\" alt=\"\" width=\"511\" height=\"77\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/102.png 511w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/102-300x45.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><\/td>\n<td width=\"301\">Now another, temporary directory is created.<\/p>\n<p>Then the required BAT file is downloaded from my GitHub repository and executed.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/103.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4817\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/103.png\" alt=\"\" width=\"261\" height=\"55\" \/><\/a><\/td>\n<td width=\"301\">The BAT file itself looks like this<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4818\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104.png\" alt=\"\" width=\"1006\" height=\"723\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104.png 1006w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104-300x216.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104-768x552.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104-600x431.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/104-905x650.png 905w\" sizes=\"(max-width: 1006px) 100vw, 1006px\" \/><\/a><\/td>\n<td width=\"301\">When the process is complete, the BAT file and the second directory are deleted.<\/p>\n<p>&nbsp;<\/p>\n<p>It should also be noted that the Teams client restarts automatically.<\/p>\n<p>&nbsp;<\/p>\n<p>In the directory C:\\MDM\\Logging we find the created log file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>What happens during the second execution of the script?<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/200.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4819\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/200.png\" alt=\"\" width=\"538\" height=\"116\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/200.png 538w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/200-300x65.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/a><\/td>\n<td width=\"301\">Here, too, it is checked whether the directory C:\\MDM\\Logging already exists. Since the script has already run through once successfully, this folder usually already exists.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4820\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201.png\" alt=\"\" width=\"900\" height=\"725\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201.png 900w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201-300x242.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201-768x619.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/201-600x483.png 600w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/a><\/td>\n<td width=\"301\">After that, we can also look at the generated log file here. (If required)<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4821\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202.png\" alt=\"\" width=\"993\" height=\"240\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202.png 993w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202-300x73.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202-768x186.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202-600x145.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/202-905x219.png 905w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/a><\/td>\n<td width=\"301\">However, if the script is actually executed again, the registry key shown here must be deleted.<\/p>\n<pre>HKCU:Software\\Microsoft\\MSB365_Teams_clear_cache_Tool<\/pre>\n<p>&nbsp;<\/p>\n<p>The script itself references this entry. If it does not exist, the script is executed accordingly, and then this entry is created.<\/p>\n<p>As already mentioned, this prevents the cache from being deleted with every restart.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3>Script packaging for Microsoft Intune<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4822\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400.png\" alt=\"\" width=\"845\" height=\"795\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400.png 845w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400-300x282.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400-768x723.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/400-600x564.png 600w\" sizes=\"(max-width: 845px) 100vw, 845px\" \/><\/a><\/td>\n<td width=\"301\">In the Endpoint Manager Portal we go to Devices &gt; Scripts<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4823\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401.png\" alt=\"\" width=\"971\" height=\"254\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401.png 971w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401-300x78.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401-768x201.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401-600x157.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/401-905x237.png 905w\" sizes=\"(max-width: 971px) 100vw, 971px\" \/><\/a><\/td>\n<td width=\"301\">Click on Add<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4824\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402.png\" alt=\"\" width=\"837\" height=\"389\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402.png 837w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402-300x139.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402-768x357.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/402-600x279.png 600w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/a><\/td>\n<td width=\"301\">Give the process a name<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4825\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403.png\" alt=\"\" width=\"886\" height=\"473\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403.png 886w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403-300x160.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403-768x410.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/403-600x320.png 600w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/td>\n<td width=\"301\">Select the script and use the configurations as shown in the picture.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4826\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404.png\" alt=\"\" width=\"777\" height=\"391\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404.png 777w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404-300x151.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404-768x386.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/404-600x302.png 600w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><\/a><\/td>\n<td width=\"301\">Assign the script to the appropriate group<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4827\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405.png\" alt=\"\" width=\"583\" height=\"581\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405.png 583w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405-300x300.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405-150x150.png 150w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/405-100x100.png 100w\" sizes=\"(max-width: 583px) 100vw, 583px\" \/><\/a><\/td>\n<td width=\"301\">Complete the deployment.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"301\"><a href=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4828\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300.png\" alt=\"\" width=\"910\" height=\"290\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300.png 910w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300-300x96.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300-768x245.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300-600x191.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2022\/05\/300-905x288.png 905w\" sizes=\"(max-width: 910px) 100vw, 910px\" \/><\/a><\/td>\n<td width=\"301\">You can find the link to the script further down in this article. Here you can see transparently how it works and how the BAT file is configured.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>As always, the following applies to my contributions: These are freely available to you and can be used free of charge. It is not allowed to resell my scripts! However, it is allowed to share them.<\/p>\n<p>I recommend to test the script in a test environment before you use it in production. I do not take any responsibility for possible damage to the infrastructure.<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p><a href=\"https:\/\/github.com\/MSB365\/ClearTeamsCache\" target=\"_blank\" rel=\"noopener\">You can find the script on my GitHub page<\/a><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>UPDATE NEW TEAMS CLIENT<\/h2>\n<div class=\"vlp-link-container vlp-layout-basic\"><a href=\"https:\/\/github.com\/MSB365\/ClearTeamsCache\/blob\/main\/ClearNEWTeamsCache.ps1\" class=\"vlp-link\" title=\"ClearTeamsCache\/ClearNEWTeamsCache.ps1 at main \u00b7 MSB365\/ClearTeamsCache\" rel=\"nofollow\" target=\"_blank\"><\/a><div class=\"vlp-layout-zone-side\"><div class=\"vlp-block-2 vlp-link-image\"><img decoding=\"async\" src=\"https:\/\/opengraph.githubassets.com\/0cf2daf8c7fe87e5ed5d8f1595a77f8d9e140fc34195ebcd1d5e6605a47a5999\/MSB365\/ClearTeamsCache\" style=\"max-width: 150px; max-height: 150px\" \/><\/div><\/div><div class=\"vlp-layout-zone-main\"><div class=\"vlp-block-0 vlp-link-title\">ClearTeamsCache\/ClearNEWTeamsCache.ps1 at main \u00b7 MSB365\/ClearTeamsCache<\/div><div class=\"vlp-block-1 vlp-link-summary\">Contribute to MSB365\/ClearTeamsCache development by creating an account on GitHub.<\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this blog article I describe the functionality (documentation) of my latest script for Microsoft Teams. It is about deleting the Teams cache for one or more users. This can be done in different ways. On the one hand, there is a really great tool by Johannes Huber under the following link: Teams Cache l\u00f6schen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4830,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1988,15,3],"tags":[],"class_list":["post-4811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ms-intune","category-ms-teams","category-powershell"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/4811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4811"}],"version-history":[{"count":3,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/4811\/revisions"}],"predecessor-version":[{"id":5558,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/4811\/revisions\/5558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/4830"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}