-
Notifications
You must be signed in to change notification settings - Fork 3
/
TokenBrokerReinstall_AllUsers.ps1
31 lines (24 loc) · 1.63 KB
/
TokenBrokerReinstall_AllUsers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Close all office applications
#Delete all credential manager entries for office 365
cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*microsoft*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
#delete the identity key
reg delete HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Common\Identity /f
#Delete Default Account registry key
reg delete HKEY_CURRENT_USER\Software\Microsoft\IdentityCRL\TokenBroker\DefaultAccount /f
#delete broker plugin for all users
$users = Get-ChildItem C:\Users
foreach ($user in $users){
$folder0 = "$($user.fullname)\AppData\Local\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy"
$folder1 = "$($user.fullname)\AppData\Local\Microsoft\IdentityCache"
$folder2 = "$($user.fullname)\AppData\Local\Microsoft\OneAuth"
#delete the broker plugin for all users
If (Test-Path $folder0) {Remove-Item $folder0 -Recurse -Force -ErrorAction silentlycontinue}
If (Test-Path $folder1) {Remove-Item $folder1 -Recurse -Force -ErrorAction silentlycontinue}
If (Test-Path $folder2) {Remove-Item $folder2 -Recurse -Force -ErrorAction silentlycontinue}
}
#Re-Install broker plugin
Add-AppxPackage -Register "$env:windir\SystemApps\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy\Appxmanifest.xml" -DisableDevelopmentMode -ForceApplicationShutdown
#Do not run dsregcmd /leave unless you have the ability to rejoin back to Azure AD
#Verify you have a local Account on the machine before running any /leave or /ForceRecovery commands as you may be required to login to re-join Azure AD without Line of sight to DC
#DSRegCMD /ForceRecovery
write-host Please open Word.exe after completing the script