Purge the Microsoft Teams Profile

Sometimes we need to purge the Microsoft Teams profile to essentially ‘reset’ the Teams client.  This could be for various reasons, such as the Outlook Teams Add-In not installing correctly or some other functionality not working such as breakout rooms.

Here is a simple VBScript can asks the user to close Teams/Outlook (and forces the closure if needs be) and purges the Teams profile.

Option Explicit
On Error Resume Next

dim svc : set svc=getobject("winmgmts:root\cimv2")
dim sQuery : sQuery="select * from win32_process where name='teams.exe' OR name='outlook.exe'"

dim wshShell : Set wshShell = Wscript.CreateObject("WScript.Shell")

dim appData : appData = wshShell.ExpandEnvironmentStrings("%APPDATA%")
dim teamsCache : teamsCache = appData & "\Microsoft\Teams"

'check specific processes are closed
	dim cproc : set cproc=svc.execquery(sQuery)
	If cproc.count = 0 Then
		Exit Do
	End If
	Msgbox "Please close Teams and Outlook.  When you have done this click OK.", 0,"Please Close Applications"
	'Forcibly close
	wshShell.Run "taskkill /F /IM teams.exe", 0, true
	wshShell.Run "taskkill /F /IM outlook.exe", 0, true
	WScript.Sleep 1000

'delete cache
wshShell.Run "cmd.exe /c RD /S /Q " & chr(34) & teamsCache & chr(34), 0, true

'recreate dir
wshShell.Run "cmd.exe /c MD " & chr(34) & teamsCache & chr(34), 0, true

Msgbox "Teams was reset successfully.  You can now launch Teams again.", 0,"Please Launch Teams"

Set svc = Nothing
Set wshShell = Nothing