Skip to content

Instantly share code, notes, and snippets.

@0ryant
Last active August 28, 2019 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0ryant/7c6ce0ea22690b7757f8dabf81bf4267 to your computer and use it in GitHub Desktop.
Save 0ryant/7c6ce0ea22690b7757f8dabf81bf4267 to your computer and use it in GitHub Desktop.
Uninstall Microsoft Teams with GPO link
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
$DebugPreference = 'continue'
Clear-Host
try
{
$user = ((Get-WmiObject -Class Win32_ComputerSystem).username).tolower()
#$user = $user -replace 'fe.',''
#$user = $user.substring(3)
$user = $user -replace '(\w{1,})\\',''
}
catch
{
Write-Debug -Message "User not logged in on $env:computername`n"
break
}
try
{
Stop-Process -Name 'Teams' -Force -ErrorAction SilentlyContinue
} catch
{
Write-Debug -Message 'Teams not currently running'
}
$TeamsPath = [IO.Path]::Combine('c:\users', $user, 'AppData', 'Local', 'Microsoft', 'Teams')
$TeamsUpdateExePath = [IO.Path]::Combine('c:\users', $user, 'AppData', 'Local', 'Microsoft', 'Teams','Update.exe')
if ((!(Test-Path -Path $TeamsPath) -or (!(Test-Path -Path $TeamsUpdateExePath))))
{
Write-Debug -Message 'Teams folders are already removed, closing'
break
}
try
{
$null = Get-CimInstance -ClassName win32_product |
Where-Object -Property name -Like -Value '*Teams*' |
Invoke-CimMethod -MethodName Uninstall
Write-Debug -Message 'Teams auto installer removed'
}
catch
{
Write-Debug -Message "Unable to uninstall the reinstaller on $env:computername - it may already be uninstalled"
}
try
{
if (Test-Path -Path $TeamsUpdateExePath)
{
Write-Debug -Message 'Uninstalling Teams process'
# Uninstall app
$proc = Start-Process -FilePath $TeamsUpdateExePath -ArgumentList '-uninstall -s' -PassThru
$proc.WaitForExit()
} else
{
Write-Debug -Message 'Teams .exe already removed...'
}
if (Test-Path -Path $TeamsPath)
{
Write-Debug -Message 'Deleting Teams directory'
Remove-Item -Path $TeamsPath -Recurse
} else
{
Write-Debug -Message 'Teams directories already removed'
}
}
catch
{
Write-Error -ErrorRecord $_
exit /b 1
}
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment