Skip to content

Commit

Permalink
Add new Teams script
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Feb 14, 2024
1 parent 8e0d002 commit 3b312d0
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 111 deletions.
187 changes: 76 additions & 111 deletions scripts/image/201_MicrosoftTeams.ps1
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
#description: Installs the latest Microsoft Teams per-machine for use on Windows 10/11 multi-session or Windows Server
#description: Installs the latest Microsoft Teams v2 per-machine for use on Windows 10/11 multi-session or Windows Server
#execution mode: Combined
#tags: Evergreen, Microsoft, Teams, per-machine
#Requires -Modules Evergreen
[System.String] $Path = "$Env:SystemDrive\Apps\Microsoft\Teams"
[System.String] $TeamsExe = "${env:ProgramFiles(x86)}\Microsoft\Teams\current\Teams.exe"

#region Functions
function Get-InstalledSoftware {
[OutputType([System.Object[]])]
[CmdletBinding()]
param ()
$UninstallKeys = @(
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$Apps = @()
foreach ($Key in $UninstallKeys) {
try {
$propertyNames = "DisplayName", "DisplayVersion", "Publisher", "UninstallString", "PSPath", "WindowsInstaller", "InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize", "SystemComponent"
$Apps += Get-ItemProperty -Path $Key -Name $propertyNames -ErrorAction "SilentlyContinue" | `
. { process { if ($null -ne $_.DisplayName) { $_ } } } | `
Where-Object { $_.SystemComponent -ne 1 } | `
Select-Object -Property @{n = "Name"; e = { $_.DisplayName } }, @{n = "Version"; e = { $_.DisplayVersion } }, "Publisher", "UninstallString", @{n = "RegistryPath"; e = { $_.PSPath -replace "Microsoft.PowerShell.Core\\Registry::", "" } }, "PSChildName", "WindowsInstaller", "InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize" | `
Sort-Object -Property "DisplayName", "Publisher"
}
catch {
throw $_
}
}
return $Apps
}
#endregion

#region Script logic
New-Item -Path $Path -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-Item -Path "$Env:ProgramData\Nerdio\Logs" -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null

#region Use Secure variables in Nerdio Manager to pass a JSON file with the variables list
if ([System.String]::IsNullOrEmpty($SecureVars.VariablesList)) {
Expand All @@ -58,107 +25,105 @@ else {
}
#endregion

#region Script logic
New-Item -Path $Path -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-Item -Path "$Env:ProgramData\Nerdio\Logs" -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null

try {
# Download Teams
Import-Module -Name "Evergreen" -Force
$App = Get-EvergreenApp -Name "MicrosoftTeams" | `
Where-Object { $_.Architecture -eq "x64" -and $_.Ring -eq "General" -and $_.Type -eq "msi" } | Select-Object -First 1
$OutFile = Save-EvergreenApp -InputObject $App -CustomPath $Path -WarningAction "SilentlyContinue"
# https://go.microsoft.com/fwlink/?linkid=2243204&clcid=0x409
# https://statics.teams.cdn.office.net/production-teamsprovision/lkg/teamsbootstrapper.exe

# https://go.microsoft.com/fwlink/?linkid=2196106
# https://statics.teams.cdn.office.net/production-windows-x64/enterprise/webview2/lkg/MSTeams-x64.msix

# Download Teams v2 Bootstrap installer
$App = [PSCustomObject]@{
Version = "2.0.0"
URI = "https://statics.teams.cdn.office.net/production-teamsprovision/lkg/teamsbootstrapper.exe"
}
$TeamsExe = Save-EvergreenApp -InputObject $App -CustomPath $Path -WarningAction "SilentlyContinue"

# Download Teams v2 MSIX installer
$App = [PSCustomObject]@{
Version = "2.0.0"
URI = "https://statics.teams.cdn.office.net/production-windows-x64/enterprise/webview2/lkg/MSTeams-x64.msix"
}
$TeamsMsi = Save-EvergreenApp -InputObject $App -CustomPath $Path -WarningAction "SilentlyContinue"
}
catch {
throw $_
}

try {
# Uninstall the existing Teams
if (Test-Path -Path $TeamsExe) {
$File = Get-ChildItem -Path $TeamsExe
if ([System.Version]$File.VersionInfo.ProductVersion -le [System.Version]$App.Version) {
Write-Information -MessageData ":: Uninstall Microsoft Teams" -InformationAction "Continue"
$LogFile = "$Env:ProgramData\Nerdio\Logs\UninstallMicrosoftTeams$($File.VersionInfo.ProductVersion).log" -replace " ", ""
# Set required IsWVDEnvironment registry value
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "IsWVDEnvironment" -PropertyType "DWORD" -Value 1 -Force -ErrorAction "SilentlyContinue" | Out-Null

# Install Teams
Write-Information -MessageData ":: Install Microsoft Teams" -InformationAction "Continue"
switch -Regex ((Get-CimInstance -ClassName "CIM_OperatingSystem").Caption) {
"Microsoft Windows Server*" {
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/x `"$($OutFile.FullName)`" /quiet /log $LogFile"
FilePath = "$Env:SystemRoot\System32\dism.exe"
ArgumentList = "/Online /Add-ProvisionedAppxPackage /PackagePath:`"$($TeamsMsi.FullName)`" /SkipLicense"
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
$result.ExitCode

$Folders = "${env:ProgramFiles(x86)}\Microsoft\Teams", `
"${env:ProgramFiles(x86)}\Microsoft\TeamsMeetingAddin", `
"${env:ProgramFiles(x86)}\Microsoft\TeamsPresenceAddin"
Remove-Item -Path $Folders -Recurse -Force -ErrorAction "Ignore"
Write-Information -MessageData ":: Install exit code: $($result.ExitCode)" -InformationAction "Continue"
}
}
}
catch {
throw $_
}

$Apps = Get-InstalledSoftware | Where-Object { $_.Name -match "Teams Machine-Wide Installer" }
foreach ($App in $Apps) {
try {
Write-Information -MessageData ":: Uninstall Microsoft Teams Machine Wide Installer" -InformationAction "Continue"
$LogFile = "$Env:ProgramData\Nerdio\Logs\UninstallMicrosoftTeamsMachineWideInstaller$($App.Version).log" -replace " ", ""
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/uninstall `"$($App.PSChildName)`" /quiet /norestart /log $LogFile"
NoNewWindow = $true
PassThru = $true
Wait = $true
ErrorAction = "Continue"
"Microsoft Windows 11 Enterprise*|Microsoft Windows 11 Pro*|Microsoft Windows 10 Enterprise*|Microsoft Windows 10 Pro*" {
$params = @{
FilePath = $TeamsExe.FullName
ArgumentList = "-p -o `"$($TeamsMsi.FullName)`""
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
Write-Information -MessageData ":: Install exit code: $($result.ExitCode)" -InformationAction "Continue"
}
$result = Start-Process @params
$result.ExitCode
}
catch {
throw $_
}
}

try {
# Install Teams
Write-Information -MessageData ":: Install Microsoft Teams" -InformationAction "Continue"
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "IsWVDEnvironment" -PropertyType "DWORD" -Value 1 -Force -ErrorAction "SilentlyContinue" | Out-Null
$LogFile = $LogFile = "$Env:ProgramData\Nerdio\Logs\MicrosoftTeams$($App.Version).log" -replace " ", ""
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/package $($OutFile.FullName) OPTIONS=`"noAutoStart=true`" ALLUSER=1 ALLUSERS=1 /quiet /log $LogFile"
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
Write-Information -MessageData ":: Install exit code: $($result.ExitCode)" -InformationAction "Continue"
}
catch {
throw $_
}
#endregion

#region Optimise Teams for multi-session without GPU support
# Delete the registry auto-start
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /v "Teams" /f | Out-Null
#region Optimise Teams
# Autostart
# HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe\TeamsTfwStartupTask
# State
# 2,1

# %LocalAppData%\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\app_settings.json
# "open_app_in_background":true
# "language": "en-AU"

# Disable auto-update
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "DisableAutoUpdate" -PropertyType "DWORD" -Value 1 -Force -ErrorAction "SilentlyContinue" | Out-Null

# Install Teams / Outlook meeting add-in
Write-Information -MessageData ":: Install Microsoft Teams meeting add-in" -InformationAction "Continue"

$TeamsPath = Get-ChildItem -Path "$Env:ProgramFiles\WindowsApps\MSTeams*" | Select-Object -ExpandProperty FullName | Sort-Object | Select-Object -First 1
$AddInInstaller = Get-ChildItem -Path $TeamsPath -Recurse -Include "MicrosoftTeamsMeetingAddinInstaller.msi"
$Version = Get-AppLockerFileInformation -Path $AddInInstaller.FullName | Select-Object -ExpandProperty "Publisher"
$AddInPath = "${Env:ProgramFiles(x86)}\Microsoft\TeamsMeetingAddin\$($Version.BinaryVersion.ToString())"

# Disable GPU acceleration by default by updating the default profile
$DesktopSetupJson = @"
{
"appPreferenceSettings": {
"runningOnClose": true,
"disableGpu": true,
"callingMWEnabledPreferenceKey": false
},
"theme": "default",
"currentWebLanguage": "$Language"
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/package `"$($AddInInstaller.FullName)`" ALLUSERS=1 TARGETDIR=`"$AddInPath`" /quiet /norestart"
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
"@
New-Item -Path "$Env:SystemDrive\Users\Default\AppData\Roaming\Microsoft\Teams" -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null
$FilePath = "$Env:SystemDrive\Users\Default\AppData\Roaming\Microsoft\Teams\desktop-config.json"
$Utf8NoBomEncoding = New-Object -TypeName "System.Text.UTF8Encoding" -ArgumentList $false
[System.IO.File]::WriteAllLines($FilePath, $DesktopSetupJson, $Utf8NoBomEncoding)
$result = Start-Process @params
Write-Information -MessageData ":: Install exit code: $($result.ExitCode)" -InformationAction "Continue"
#endregion
164 changes: 164 additions & 0 deletions scripts/image/201_MicrosoftTeamsClassic.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#description: Installs the latest Microsoft Teams per-machine for use on Windows 10/11 multi-session or Windows Server
#execution mode: Combined
#tags: Evergreen, Microsoft, Teams, per-machine
#Requires -Modules Evergreen
[System.String] $Path = "$Env:SystemDrive\Apps\Microsoft\Teams"
[System.String] $TeamsExe = "${env:ProgramFiles(x86)}\Microsoft\Teams\current\Teams.exe"

#region Functions
function Get-InstalledSoftware {
[OutputType([System.Object[]])]
[CmdletBinding()]
param ()
$UninstallKeys = @(
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$Apps = @()
foreach ($Key in $UninstallKeys) {
try {
$propertyNames = "DisplayName", "DisplayVersion", "Publisher", "UninstallString", "PSPath", "WindowsInstaller", "InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize", "SystemComponent"
$Apps += Get-ItemProperty -Path $Key -Name $propertyNames -ErrorAction "SilentlyContinue" | `
. { process { if ($null -ne $_.DisplayName) { $_ } } } | `
Where-Object { $_.SystemComponent -ne 1 } | `
Select-Object -Property @{n = "Name"; e = { $_.DisplayName } }, @{n = "Version"; e = { $_.DisplayVersion } }, "Publisher", "UninstallString", @{n = "RegistryPath"; e = { $_.PSPath -replace "Microsoft.PowerShell.Core\\Registry::", "" } }, "PSChildName", "WindowsInstaller", "InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize" | `
Sort-Object -Property "DisplayName", "Publisher"
}
catch {
throw $_
}
}
return $Apps
}
#endregion

#region Script logic
New-Item -Path $Path -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-Item -Path "$Env:ProgramData\Nerdio\Logs" -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null

#region Use Secure variables in Nerdio Manager to pass a JSON file with the variables list
if ([System.String]::IsNullOrEmpty($SecureVars.VariablesList)) {
[System.String] $Language = "en-AU"
}
else {
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$params = @{
Uri = $SecureVars.VariablesList
UseBasicParsing = $true
ErrorAction = "Stop"
}
$Variables = Invoke-RestMethod @params
[System.String] $Language = $Variables.$AzureRegionName.Language
}
catch {
throw $_
}
}
#endregion

try {
# Download Teams
Import-Module -Name "Evergreen" -Force
$App = Get-EvergreenApp -Name "MicrosoftTeams" | `
Where-Object { $_.Architecture -eq "x64" -and $_.Ring -eq "General" -and $_.Type -eq "msi" } | Select-Object -First 1
$OutFile = Save-EvergreenApp -InputObject $App -CustomPath $Path -WarningAction "SilentlyContinue"
}
catch {
throw $_
}

try {
# Uninstall the existing Teams
if (Test-Path -Path $TeamsExe) {
$File = Get-ChildItem -Path $TeamsExe
if ([System.Version]$File.VersionInfo.ProductVersion -le [System.Version]$App.Version) {
Write-Information -MessageData ":: Uninstall Microsoft Teams" -InformationAction "Continue"
$LogFile = "$Env:ProgramData\Nerdio\Logs\UninstallMicrosoftTeams$($File.VersionInfo.ProductVersion).log" -replace " ", ""
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/x `"$($OutFile.FullName)`" /quiet /log $LogFile"
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
$result.ExitCode

$Folders = "${env:ProgramFiles(x86)}\Microsoft\Teams", `
"${env:ProgramFiles(x86)}\Microsoft\TeamsMeetingAddin", `
"${env:ProgramFiles(x86)}\Microsoft\TeamsPresenceAddin"
Remove-Item -Path $Folders -Recurse -Force -ErrorAction "Ignore"
}
}
}
catch {
throw $_
}

$Apps = Get-InstalledSoftware | Where-Object { $_.Name -match "Teams Machine-Wide Installer" }
foreach ($App in $Apps) {
try {
Write-Information -MessageData ":: Uninstall Microsoft Teams Machine Wide Installer" -InformationAction "Continue"
$LogFile = "$Env:ProgramData\Nerdio\Logs\UninstallMicrosoftTeamsMachineWideInstaller$($App.Version).log" -replace " ", ""
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/uninstall `"$($App.PSChildName)`" /quiet /norestart /log $LogFile"
NoNewWindow = $true
PassThru = $true
Wait = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
$result.ExitCode
}
catch {
throw $_
}
}

try {
# Install Teams
Write-Information -MessageData ":: Install Microsoft Teams" -InformationAction "Continue"
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Force -ErrorAction "SilentlyContinue" | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "IsWVDEnvironment" -PropertyType "DWORD" -Value 1 -Force -ErrorAction "SilentlyContinue" | Out-Null
$LogFile = $LogFile = "$Env:ProgramData\Nerdio\Logs\MicrosoftTeams$($App.Version).log" -replace " ", ""
$params = @{
FilePath = "$Env:SystemRoot\System32\msiexec.exe"
ArgumentList = "/package $($OutFile.FullName) OPTIONS=`"noAutoStart=true`" ALLUSER=1 ALLUSERS=1 /quiet /log $LogFile"
NoNewWindow = $true
Wait = $true
PassThru = $true
ErrorAction = "Continue"
}
$result = Start-Process @params
Write-Information -MessageData ":: Install exit code: $($result.ExitCode)" -InformationAction "Continue"
}
catch {
throw $_
}
#endregion

#region Optimise Teams for multi-session without GPU support
# Delete the registry auto-start
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /v "Teams" /f | Out-Null

# Disable GPU acceleration by default by updating the default profile
$DesktopSetupJson = @"
{
"appPreferenceSettings": {
"runningOnClose": true,
"disableGpu": true,
"callingMWEnabledPreferenceKey": false
},
"theme": "default",
"currentWebLanguage": "$Language"
}
"@
New-Item -Path "$Env:SystemDrive\Users\Default\AppData\Roaming\Microsoft\Teams" -ItemType "Directory" -Force -ErrorAction "SilentlyContinue" | Out-Null
$FilePath = "$Env:SystemDrive\Users\Default\AppData\Roaming\Microsoft\Teams\desktop-config.json"
$Utf8NoBomEncoding = New-Object -TypeName "System.Text.UTF8Encoding" -ArgumentList $false
[System.IO.File]::WriteAllLines($FilePath, $DesktopSetupJson, $Utf8NoBomEncoding)
#endregion

0 comments on commit 3b312d0

Please sign in to comment.