Outdated Microsoft Teams - Clients Installed by Admin

  • 20 October 2023
  • 0 replies
  • 127 views

Badge

Hi everyone,

I found and modified this PowerShell script online, we were running into an issue where our process of installing Teams had an admin touch the computer, and it’d create an outdated version on the Admin account, then leave it. 

For the following Worklet, simply put in your target version (the version you’re currently using) and what users should be targeted (whoever installed the version) then run on the necessary machines. 

Evalution Code:

$TargetVersion = "PUT DESIRED VERSION HERE"

$OutdatedUsers = @(PUT OUTDATED USER HERE)

# Get all Users
$Users = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"

# Process all Users
$Users | ForEach-Object {

    #Locate installation folder
    $localAppData = "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams"
    
    # If teams exists for user > check version and add to array if outdated.
    If (Test-Path "$($localAppData)\Current\Teams.exe") 
    {
      $InstalledVersion = (Get-ChildItem "$($localAppData)\current\Teams.exe").VersionInfo.FileVersion
        If ($InstalledVersion -lt $TargetVersion)
        {
            $OutdatedUsers += $_.Name
        }
    }
}

# Set Compliance
If ($OutdatedUsers.Count -gt 0)
    {
        return $false
    }
else 
    {
        return $true
    }

 

Remediation Code: 

$TargetVersion = "PUT DESIRED VERSION HERE"

function unInstallTeams($path) {
    Write-Host "Uninstalling..."
    $clientInstaller = "$($path)\Update.exe"
    Start-Process -FilePath "$clientInstaller" -ArgumentList "--uninstall /s" -PassThru -Wait -ErrorAction SilentlyContinue
}

# Remove Teams for all User profiles if less than target version
# Get all Users
$Users = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"

# Process all Users
$Users | ForEach-Object {
        Write-Host "Process user: $($_.Name)" -ForegroundColor Yellow

        #Locate installation folder
        $localAppData = "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams"
        $programData = "$($env:ProgramData)\$($_.Name)\Microsoft\Teams"
        
        If (Test-Path "$($localAppData)\Current\Teams.exe") 
        {
          $InstalledVersion = (Get-ChildItem "$($localAppData)\current\Teams.exe").VersionInfo.FileVersion
            If ($InstalledVersion -lt $TargetVersion)
            {
                Write-Host "Teams (LocalAppData) outdated for user $($_.Name)"
                unInstallTeams($localAppData)
            }

            elseif ($InstalledVersion -ge $TargetVersion)
            {
                Write-Host "Teams (LocalAppData) is up-to-date for user $($_.Name)"
            }
        }

        elseif (Test-Path "$($programData)\Current\Teams.exe") 
        {
            $InstalledVersion = (Get-ChildItem "$($programData)\current\Teams.exe").VersionInfo.FileVersion
            If ($InstalledVersion -lt $TargetVersion)
            {
                Write-Host "Teams (ProgramData) outdated for user $($_.Name)"
                unInstallTeams($programData)
            }
            elseif ($InstalledVersion -ge $TargetVersion)
            {
                Write-Host "Teams (ProgramData) is up-to-date for user $($_.Name)"
            }
        }  

        Else
        {
          write-Host "Teams not present for user $($_.Name)"  
        }
}


0 replies

Be the first to reply!

Reply