I tried various methods here without success until I combined various methods together. A bit of "a belt and braces" approach. Or a scatter gun approach and hoping something worked. Which it did. I now need a more elegant script and gradually remove the unnecessary commands. I know I have del and ren commands which probably conflict.
Anyway, this worked on a test laptop. When I open Teams now, its like a brand new install without any accounts remembered.
I can't take all the credit or blame. Like I said, I copied parts of other scripts here and other parts I found on other forums......
This runs as a batch file in the startup folder of the generic account that logs into Windows on a shared conference laptop.
That's why we don't want individual users' Teams accounts appearing in the accounts to choose.
pushd "C:\Users<USERNAME>\Downloads" 2>nul && ( rd /Q /S "C:\Users<USERNAME>\Downloads" 2>nul & popd )
taskkill /F /IM Teams.exe
taskkill /F /IM msteams.exe
taskkill /F /IM "Microsoft.AAD.BrokerPlugin.exe"
del "C:\Users<USERNAME>\AppData\Roaming\Microsoft\Teams\desktop-config.json" /q
rmdir "C:\Users<USERNAME>\AppData\Local\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy" /s /Q
del "C:\Users<USERNAME>\AppData\Local\Packages\MicrosoftTeams_8wekyb3d8bbwe\*.*" /F /s /Q
del "C:\Users<USERNAME>\AppData\Roaming\Microsoft\Windows\Recent\*.*" /F /s /Q
del "C:\Users<USERNAME>\AppData\Roaming\Microsoft\Windows\Network Shortcuts\*.*" /F /s /Q
ren C:\Users<USERNAME>\AppData\Local\Microsoft\OneAuth\accounts accounts_old
ren C:\Users<USERNAME>\AppData\Local\Packages\MSTeams_8wekyb3d8bbwe MSTeams_8wekyb3d8bbwe_OLD
ren C:\Users<USERNAME>\AppData\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy" "Microsoft.AAD.BrokerPlugin_OLD
ren C:\Users<USERNAME>\AppData\Microsoft\OneAuth OneAuth_OLD
ren C:\Users<USERNAME>\AppData\Microsoft\TokenBroker TokenBroker_OLD
ren C:\Users<USERNAME>\AppData\Microsoft\IdentityCache IdentityCache_OLD
ren C:\Users<USERNAME>\AppData\Microsoft\Teams Teams_OLD
reg delete HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Teams /f
Feel free to recommend changes to make it more elegant
Regards,
Michael