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

Aran Billen 271 Reputation points
2024-01-24T09:29:07.0066667+00:00

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

}

Microsoft Intune Configuration
Microsoft Intune Configuration
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Configuration: The process of arranging or setting up computer systems, hardware, or software.
1,650 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,064 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,856 questions
0 comments No comments
{count} votes

Accepted answer
  1. Simon Ren-MSFT 28,556 Reputation points Microsoft Vendor
    2024-01-24T14:08:30.2566667+00:00

    Hi @Aran Billen ,

    Thanks very much for your feedback and sharing. We're glad that the issue is gone now. It's appreciated that you could click "Accept Answer" to the helpful reply, this will help other users to search for useful information more quickly. Here's a short summary for the problem.

    Problem/Symptom:

    The script removing personal Teams on Windows 11 devices 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.

    Solution/Workaround:

    Use below PowerShell script from Intune to remove personal Teams on Windows 11 devices

    teams

    Thanks again for your time. Have a nice day!

    Best regards,

    Simon


    If the response is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Aran Billen 271 Reputation points
    2024-01-24T12:31:51.31+00:00

    This worked

    #Kill Teams Personal EXE if running
    TASKKILL /IM msteams.exe /f
    
    #Remove it
    Get-AppxPackage MicrosoftTeams -allusers | Remove-AppxPackage -allusers
    
    Exit 0
    
    
    1 person found this answer helpful.
    0 comments No comments