Tech Community Live: Microsoft Intune
Mar 20 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community
SOLVED

Issue with Intune Script: Successful Report, but Ineffective Removal of Personal Teams on Windows 11

Steel Contributor

Hello everyone,

I've encountered an issue with a script that performs flawlessly when executed manually on the device. However, when running the same script via Intune, it reports success but doesn't effectively achieve its goal. Despite restarting the device, the problem persists. The script is designed to remove personal Teams on Windows 11 devices. Any insights or assistance in resolving this discrepancy would be greatly appreciated. What do I need to to the script to get it to work

Here is the script:

$MSTeams = "MicrosoftTeams"

$WinPackage = Get-AppxPackage | Where-Object {$_.Name -eq $MSTeams}

$ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq $WinPackage }

If ($null -ne $WinPackage)

{

Remove-AppxPackage -Package $WinPackage.PackageFullName

}

If ($null -ne $ProvisionedPackage)

{

Remove-AppxProvisionedPackage -online -Packagename $ProvisionedPackage.Packagename

}

$WinPackageCheck = Get-AppxPackage | Where-Object {$_.Name -eq $MSTeams}

$ProvisionedPackageCheck = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq $WinPackage }

If (($WinPackageCheck) -or ($ProvisionedPackageCheck))

{

throw

} 

 

1 Reply
best response confirmed by AB21805 (Steel Contributor)
Solution
Found a fix : #Kill Teams Personal EXE if running
TASKKILL /IM msteams.exe /f

#Remove it
Get-AppxPackage MicrosoftTeams -allusers | Remove-AppxPackage -allusers

Exit 0
1 best response

Accepted Solutions
best response confirmed by AB21805 (Steel Contributor)
Solution
Found a fix : #Kill Teams Personal EXE if running
TASKKILL /IM msteams.exe /f

#Remove it
Get-AppxPackage MicrosoftTeams -allusers | Remove-AppxPackage -allusers

Exit 0

View solution in original post