Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9162

Logout from Office 365 with Powershell

$
0
0

We got a public computer with windows 10 and the office365-suite in one of our meetings room at my company. On this computer people shall login into their company-accounts, so the office-software is licensed. Some of them don't logout when they leave. They just shutdown the computer. If a next user now starts one of the office programs, the last user will be logged in.

To prevent this, I'm trying to write an powershell script which deleted the cached credentials.

For Microsoft-Teams if found a script which works like a charm.

#Stop Teams process Get-Process -ProcessName Teams -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 3Write-Host "Teams Process Sucessfully Stopped" #Clear Team Cachetry{Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\databases" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\cache" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\gpucache" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\Indexeddb" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\Local Storage" | Remove-Item -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path $env:APPDATA\"Microsoft\teams\tmp" | Remove-Item -Recurse -ErrorAction SilentlyContinueWrite-Host "Teams Cache Cleaned" }catch{echo $_ }#Remove Credential from Credential manager$credential = cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*msteams*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}#Remove Reg.Key$Regkeypath= "HKCU:\Software\Microsoft\Office\Teams" $value = (Get-ItemProperty $Regkeypath).HomeUserUpn -eq $nullIf ($value -eq $False) {   Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Office\Teams" -Name "HomeUserUpn"  Write-Host "The registry value Sucessfully removed" } Else { Write-Host "The registry value does not exist"}#Get Desktop-config.json$TeamsFolders = "$env:APPDATA\Microsoft\teams"try{    $SourceDesktopConfigFile = "$TeamsFolders\desktop-config.json"    $desktopConfig = (Get-Content -Path $SourceDesktopConfigFile | ConvertFrom-Json)}catch{ Write-Host "Failed to open Desktop-config.json" }#Overwrite the desktop-config.jsonWrite-Host "Modify desktop-Config.Json"try{    $desktopConfig.isLoggedOut = $true    $desktopConfig.upnWindowUserUpn =""; #The email used to sign in    $desktopConfig.userUpn ="";    $desktopConfig.userOid ="";    $desktopConfig.userTid = "";    $desktopConfig.homeTenantId ="";    $desktopConfig.webAccountId="";    $desktopConfig | ConvertTo-Json -Compress | Set-Content -Path $SourceDesktopConfigFile -Force}catch{ Write-Host "Failed to overwrite desktop-config.json" }Write-Host "Modify desktop-Config.Json - Finished"#Delete the Cookies file. This is a fix for when the joining as anonymous, and prevents the last used guest name from being reused.Get-ChildItem "$TeamsFolders\Cookies" | Remove-Item#Lastly delete the storage.json, this corrects some error that MSTeams otherwise would have when logging in again.Get-ChildItem "$TeamsFolders\storage.json" | Remove-Item#Try to remove the Link School/Work account if there was one. It can be created if the first time you sign in, the user all$LocalPackagesFolder ="$env:LOCALAPPDATA\Packages"$AADBrokerFolder = Get-ChildItem -Path $LocalPackagesFolder -Recurse -Include "Microsoft.AAD.BrokerPlugin_*";$AADBrokerFolder = $AADBrokerFolder[0];Get-ChildItem "$AADBrokerFolder\AC\TokenBroker\Accounts" | Remove-Item -Recurse -Force

I already know that Office365 saves the credentials in these registry-keysComputer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\Identity

But if I start some office-program again the auto-login just needs some more seconds.So I'm asking for some other places, where office365 could cache/save the credentials.


Viewing all articles
Browse latest Browse all 9162

Trending Articles