Search code examples
powershellmicrosoft-teams

Powershell Script to reinstall Microsoft teams, Not able to find teams install


Currently I am trying to write a power shell script that will uninstall then install Microsoft Teams. I have never written a power shell script before and I am having trouble having the script get the initial teams installation so I can uninstall it.

This is what I have written so far, I saw two ways of finding the teams install online and neither is able to find it so I am kinda lost, any help would be much appreciated. (I know both are commented out I just did it like this for formatting in this question.)

Write-Host "-------------------------------------`n"
# Prompt for credentials
$credential = Get-Credential
$username = $credential.Username
$password = $credential.GetNetworkCredential().Password

Write-Host "Finding teams`n"
# Find teams 1
#$teamsapp = Get-AppxPackage -Name Microsoft.Teams


# Find teams 2
#$teamsapp = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq "Microsoft Teams" }


# Check if installed
if ($teamsapp) {
    Write-Host "Microsoft Teams is installed."
} else {
    Write-Host "Microsoft Teams is not installed."
}

`


Solution

  • Teams is a bit tricky because it installs per user, not per computer. Assuming you're running the script under the user's account, you can check the following registry location using Get-ChildItem:

    Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Teams

    This code worked for me:

    Get-ChildItem -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' | Where-Object { $_.Name -like '*Teams' }
    

    You should be able to use the "QuietUninstallString" property of the result to get the command needed to uninstall Teams.

    As a side note, consider looking into the Teams Machine Wide Installer for deploying teams. It installs to the computer and runs at logon for each user to detect if Teams is installed to their AppData folder. If not, it installs it automatically. This lets you avoid having to run as the user or loop through all the users AppData folder to manipulate user apps.