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

Aran Billen 596 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,729 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,374 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,085 questions
0 comments No comments
{count} votes

Accepted answer
  1. Simon Ren-MSFT 30,496 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.

2 additional answers

Sort by: Most helpful
  1. Aran Billen 596 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.

  2. Jacques Landry 5 Reputation points
    2024-04-12T16:20:05.9+00:00

    This will remove the built-in Microsoft Teams for personal use.

    Deploy this powershell Script in Intune with no error!

    Run this script using the logged on credentials - No

    Enforce script signature check - No

    Run script in 64 bit PowerShell Host - Yes

    Assigned to Windows 11 devices

    # Kill Teams Personal EXE if running
    TASKKILL /IM msteams.exe /f
    # Wait for 30 seconds to ensure the processes have been stopped
    Start-Sleep -Seconds 30
    # Remove it
    Get-AppxPackage MicrosoftTeams -allusers | Remove-AppxPackage -allusers
    # Check if Teams is still installed
    $teams = Get-AppxPackage -AllUsers | Where-Object {$_.Name -eq "MicrosoftTeams"}
    if ($null -eq $teams) {
        # If Teams is not found, exit with code 0
        exit 0
    } else {
        # If Teams is still found, exit with a non-zero code
        exit 1
    }
    
    1 person found this answer helpful.
    0 comments No comments