Teams Deployment and Update for Server 2019, 2022, and 2025

While testing out the newer versions of Teams for all user installs, I noticed that it was no longer updating properly via the launch, close, relaunch process. So I went back to the PowerShell drawing board and created a brand new scripted deployment process for Teams that will properly install the latest version of Teams, and remove Teams and the Outlook Teams add-in, then install it during an update process.

As 2019 uses different installation methods than 2022/2025, you will see in the script that detection for proper branching. Also for new installs if you don't have the proper Dot Net Framework 4.8 or later installed, a requirement for the Outlook add-in, the script will install it for you. It also will reboot after that process, restarting the PowerShell script after that reboot will continue the process.

I worked to address any of the false red error messages from showing in the log and screen. But if you experience anything, let me know so I can adjust the script.

As with all PowerShell Scripts, make sure to sign it with an internal domain certificate authority to prevent having to adjust your Execution Policy settings.

#Teams Install
$winver = Get-ComputerInfo | Select-Object -ExpandProperty WindowsProductName

$TeamsKeyTest = test-path -path "HKLM:\SOFTWARE\Microsoft\Teams"
If ($TeamsKeyTest) { $TeamUpdateRegistryTest = (Get-Item "HKLM:\SOFTWARE\Microsoft\Teams").Property -contains "disableAutoUpdate" }else {}
If ($TeamUpdateRegistryTest) { 
    Write-Output "Check to see if Teams auto update is disabled, and remove that setting."
    Write-Output "It will be re-enabled at the end of the process."
    Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "disableAutoUpdate" }else {}

$TeamInstallPath = "C:\Program Files\WindowsApps\MSTeams_*"
$TeamInstallCheck = test-path -PathType container $TeamInstallPath
#Remove Teams if it is already installed.
If ($TeamInstallCheck) {

    # Remove current Teams add-in for Outlook
    Write-Output "Remove Current Teams Add-in for Outlook if it is installed"
    Uninstall-Package -Name "Microsoft Teams Meeting Add-in for Microsoft Office" -Force
    Remove-Item "C:\Program Files (x86)\Microsoft\TeamsMeetingAddin\" -Force -Recurse

    #2019 Install

    If ($winver -like "Windows Server 2019*") {

        $TeamDownloadURI = "https://go.microsoft.com/fwlink/?linkid=2196106"
        $TeamPath = Join-Path "$($env:TEMP)" "MSTeams-x64.msix"
        Write-Output "Downloading Latest Teams MSIX file"
        (New-Object System.Net.WebClient).DownloadFile($TeamDownloadURI, $TeamPath)
        $DISM = "c:\windows\system32\Dism.exe"
        $Switches = " /Online /Remove-ProvisionedAppxPackage /PackagePath:$TeamPath /SkipLicense"
        Write-output "Uninstalling Existing Teams for Windows Server 2019"
        $Team2Installproc = Start-Process -FilePath $DISM -ArgumentList $Switches -PassThru -Wait
        $Team2Installproc.WaitForExit()
    }
    else {

    #2022/2025 Install

        $TeamDownloadURI = "https://go.microsoft.com/fwlink/?linkid=2243204&clcid=0x409"
        $TeamPath = Join-Path "$($env:TEMP)" "teamsbootstrapper.exe"
        Write-Output "Downloading Latest Teams Bootstrapper file"
        (New-Object System.Net.WebClient).DownloadFile($TeamDownloadURI, $TeamPath)
        $Execute2Setup = " -x"
        Write-output "UnInstalling Existing Teams for Windows Server 2022/2025"
        $Team2Installproc = Start-Process -FilePath $TeamPath -ArgumentList $Execute2Setup -PassThru -Wait
        $Team2Installproc.WaitForExit()

    }
Start-Sleep 30
}
else {
    Write-Output "Teams is not currently installed."
}

#Download and install Teams
# Server 2019
If ($winver -like "Windows Server 2019*") {

    #Check for DotNet 4.8 or later - required for the Teams add-in for Outlook
    if ((Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge 528049) {
        Write-Host "Dot Net is up to date."
    }
    else {
        Write-output "Dot Net Framework 4.8 or later is not installed."
        Write-output "This is required for the Teams add-in for Outlook"
        Write-output "After it installs your machine will reboot."
        $DotNetDownloadURI = "https://go.microsoft.com/fwlink/?linkid=2088631"
        $DotNetPath = Join-Path "$($env:TEMP)" "NDP48-x86-x64-AllOS-ENU.exe"
        (New-Object System.Net.WebClient).DownloadFile($DotNetDownloadURI, $DotNetPath)
        $DotNetSwitches = "/q"
        $DotNetInstallProc = Start-Process -FilePath $DotNetPath -ArgumentList $DotNetSwitches  -PassThru -Wait
        $DotNetInstallProc.WaitForExit()
    }
    New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Appx" -Name "AllowAllTrustedApps" -Value "00000001" -PropertyType DWORD -Force
    if (!$TeamPath) {
        Write-Host "Download latest Teams installer"
        $TeamDownloadURI = "https://go.microsoft.com/fwlink/?linkid=2196106"
        $TeamPath = Join-Path "$($env:TEMP)" "MSTeams-x64.msix"
        Write-Output "Downloading Now"
        (New-Object System.Net.WebClient).DownloadFile($TeamDownloadURI, $TeamPath)
    }else{}
    $DISM = "c:\windows\system32\Dism.exe"
    $Switches = " /Online /Add-ProvisionedAppxPackage /PackagePath:$TeamPath /SkipLicense"
    Write-output "Installing Teams for Windows Server 2019"
    $Team2Installproc = Start-Process -FilePath $DISM -ArgumentList $Switches  -PassThru -Wait
    $Team2Installproc.WaitForExit()
}
else {

#2022/2025 Install

    #Check for DotNet 4.8 or later - required for the Teams add-in for Outlook
    if ((Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge 528049) {
        Write-Host "Dot Net is up to date."
    }
    else {
        Write-output "Dot Net Framework 4.8 or later is not installed."
        Write-output "This is required for the Teams add-in for Outlook"
        Write-output "After it installs your machine will reboot."
        $DISM = "c:\windows\system32\Dism.exe"
        $DotNetSwitches = " /online /Enable-Feature /FeatureName:NetFx4 /All"
        $DotNetInstallProc = Start-Process -FilePath $DISM -ArgumentList $DotNetSwitches  -PassThru -Wait
        $DotNetInstallProc.WaitForExit()
    }
    if (!$TeamPath) {       
        Write-Host "Download latest Teams installer"
        $TeamDownloadURI = "https://go.microsoft.com/fwlink/?linkid=2243204&clcid=0x409"
        $TeamPath = Join-Path "$($env:TEMP)" "teamsbootstrapper.exe"
        Write-Output "Downloading Now"
        (New-Object System.Net.WebClient).DownloadFile($TeamDownloadURI, $TeamPath)}else{}
    $Execute2Setup = " -p"
    Write-output "Installing Teams for Windows Server 2022/2025"
    $Team2Installproc = Start-Process -FilePath $TeamPath -ArgumentList $Execute2Setup -PassThru -Wait
    $Team2Installproc.WaitForExit()

}
Start-Sleep 30
Write-output "Teams has completed installation, now installing the Teams Outlook Add-in"
# Install latest Teams Meeting Add-in
$UpdatedTeams = (Get-ChildItem -Path "C:\Program Files\WindowsApps" -Filter "MSTeams_*" -Directory).Fullname | Sort-Object name | Select-Object -First 1
$installableversion = Get-AppLockerFileInformation -Path $UpdatedTeams"\MICROSOFTTEAMSMEETINGADDININSTALLER.MSI" | Select-Object -ExpandProperty Publisher | Select-Object BinaryVersion
$getversionnumber = $installableversion.BinaryVersion.toString()
$TeamsAddinInstall = start-process -filepath "C:\Windows\System32\msiexec.exe"-argumentList '/i MicrosoftTeamsMeetingAddinInstaller.msi /qn ALLUSERS=1 /norestart TARGETDIR="C:\Program Files (x86)\Microsoft\TeamsMeetingAddin\', $getversionnumber, '"' -WorkingDirectory $UpdatedTeams -Passthru -Wait
$TeamsAddinInstall.WaitForExit()

#Disable Teams Auto-Updates for users.
$TeamsKeyTest = test-path -path "HKLM:\SOFTWARE\Microsoft\Teams"
If ($TeamsKeyTest) {New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "disableAutoUpdate" -Value "00000001" -PropertyType DWORD -Force}
else { 
    New-Item "HKLM:\SOFTWARE\Microsoft\Teams"
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "disableAutoUpdate" -Value "00000001" -PropertyType DWORD -Force
}