Update June 2023: This can now also be completed using Settings Catalog:
Teams Chat is an annoying addition to Windows 11 and whilst you can remove the package itself, it doesn’t actually fully remove so you then need to push out extra policies.
Whilst updating my de-bloat script I wanted to include the ability to fully remove it simply using PowerShell (and ideally Proactive Remediations in case a rogue update brings it back!)
If you are already using my bloat script, it already does this for you, but if you have a live environment, here are the scripts you need (also on GitHub)
Detection Script
This is fairly straight forward, simply look for the AppX package. To be extra careful I’m checking for it via the two commands and incrementing a counter if it finds either
##Detect Teams Chat
$MSTeams = "MicrosoftTeams"
##Look for Package
$WinPackage = Get-AppxPackage -allusers | Where-Object {$_.Name -eq $MSTeams}
$ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq $WinPackage }
##Set a detection counter
$detection = 0
##If the package is found, increment the counter
if ($null -ne $WinPackage)
{
$detection++
}
if ($null -ne $ProvisionedPackage)
{
$detection++
}
if ($detection -eq 0) {
write-host "Teams Chat not found, compliance met"
exit 0
}
else {
write-host "Teams Chat found, compliance not met"
exit 1
}
Remediation Script
This is more complex.
First we remove the appxpackage which is easy enough.
To unpin and stop it returning though, we need to add some registry keys, you would think easy enough, but one is permissions locked! For this, I’m using the excellent SetACL tool (from here), downloading it to the machine, tweaking the permissions and then removing the tool again.
#Remove Teams Chat
$MSTeams = "MicrosoftTeams"
$WinPackage = Get-AppxPackage -allusers | Where-Object {$_.Name -eq $MSTeams}
$ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq $WinPackage }
If ($null -ne $WinPackage)
{
Remove-AppxPackage -Package $WinPackage.PackageFullName -AllUsers
}
If ($null -ne $ProvisionedPackage)
{
Remove-AppxProvisionedPackage -online -Packagename $ProvisionedPackage.Packagename -AllUsers
}
##Tweak reg permissions
invoke-webrequest -uri "https://github.com/andrew-s-taylor/public/raw/main/De-Bloat/SetACL.exe" -outfile "C:\Windows\Temp\SetACL.exe"
C:\Windows\Temp\SetACL.exe -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn setowner -ownr "n:administrators"
C:\Windows\Temp\SetACL.exe -on "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications" -ot reg -actn ace -ace "n:administrators;p:full"
Remove-Item C:\Windows\Temp\SetACL.exe -recurse
##Stop it coming back
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications"
If (!(Test-Path $registryPath)) {
New-Item $registryPath
}
Set-ItemProperty $registryPath ConfigureChatAutoInstall -Value 0
##Unpin it
$registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Chat"
If (!(Test-Path $registryPath)) {
New-Item $registryPath
}
Set-ItemProperty $registryPath "ChatIcon" -Value 2
write-host "Removed Teams Chat"
This should hopefully remove the pain of users clicking the wrong link!
Hi Andrew,
Tried this one just now. Getting the below:
“Set-ItemProperty : Requested registry access is not allowed.
At C:\WINDOWS\IMECache\HealthScripts\d7b14263-66a6-4f19-9486-330e011581e9_1\remediate.ps1:28 char:1
+ Set-ItemProperty $registryPath ConfigureChatAutoInstall -Value 0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH…\Communications:String) [Set-ItemProperty], Securit
yException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.SetItemPropertyCommand”
Any ideas?
Is it running in System/64 bit context?
Thanks for the response.
Settings
Detection script
Yes
Remediation script
Yes
Run this script using the logged-on credentials
No
Enforce script signature check
No
Run script in 64-bit PowerShell
No
Now, I’m targeting devices here if it makes any difference.
Thanks in advance.
Set this to Yes
Run script in 64-bit PowerShell
No
But the teams is still installed and searchable in start menu..
Are you getting any errors? It sounds like something has gone wrong
And it can be completed by the following configuration policy https://learn.microsoft.com/en-us/troubleshoot/windows-client/application-management/managing-teams-chat-icon-windows-11 to remove the icon in the task bar 🙂