PowerShell Script for Microsoft Teams Client Deployment
How to create a PowerShell script for automating the deployment of the Microsoft Teams desktop client for Windows?
Instructions
- Download the Teams client installer from Microsoft.
- Run the script and specify the -SourcePath for the installer.
Example:
From PowerShell
.InstallMSTeams.ps1 -Source \ShareMicrosoftTeams
Explanation:
Using the example command above, the script will look in \ShareMicrosoftTeams for the Teams_Windows_x64.exe file, and launch a silent installation of the Teams client.
To automate the deployment i have create another article to explain "How to deploy Microsoft Teams using GPO"
Script
(copy to notepad and save it as InstallMSTeams.ps1)
#requires -version 4
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$SourcePath
)
function DoInstall {
$Installer = "$($SourcePath)Teams_windows_x64.exe"
If (!(Test-Path $Installer)) {
throw "Unable to locate Microsoft Teams client installer at $($installer)"
}
Write-Host "Attempting to install Microsoft Teams client"
try {
$process = Start-Process -FilePath "$Installer" -ArgumentList "-s" -Wait -PassThru -ErrorAction STOP
if ($process.ExitCode -eq 0)
{
Write-Host -ForegroundColor Green "Microsoft Teams setup started without error."
}
else
{
Write-Warning "Installer exit code $($process.ExitCode)."
}
}
catch {
Write-Warning $_.Exception.Message
}
}
#Check if Office is already installed, as indicated by presence of registry key
$installpath = "$($env:LOCALAPPDATA)MicrosoftTeams"
if (-not(Test-Path "$($installpath)Update.exe")) {
DoInstall
}
else {
if (Test-Path "$($installpath).dead") {
Write-Host "Teams was previously installed but has been uninstalled. Will reinstall."
DoInstall
}
}