# Download and install New Teams $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri "https://statics.teams.cdn.office.net/production-windows-x64/enterprise/webview2/lkg/MSTeams-x64.msix" -OutFile "$env:temp\MSTeams-x64.msix" Add-AppxPackage -Path "$env:TEMP\MSTeams-x64.msix" # Install Teams Outlook add-in $TeamsDir = (Get-AppxPackage MSTeams).InstallLocation Start-Process msiexec.exe -Wait -ArgumentList "/i `"$TeamsDir\MicrosoftTeamsMeetingAddinInstaller.msi`" ALLUSERS=1 /qn TARGETDIR=`"C:\Program Files\TeamsMeetingAddin`"" # Register 'msteams' protocol New-Item -Path "HKLM:\SOFTWARE\Classes\msteams" -Force | Out-Null New-ItemProperty -Path "HKLM:\SOFTWARE\Classes\msteams" -Name "(Default)" -Value "URL:msteams" -PropertyType String -Force | Out-Null New-ItemProperty -Path "HKLM:\SOFTWARE\Classes\msteams" -Name "URL Protocol" -Value "" -PropertyType String -Force | Out-Null New-Item -Path "HKLM:\SOFTWARE\Classes\msteams\shell\open\command" -Force | Out-Null New-ItemProperty -Path "HKLM:\SOFTWARE\Classes\msteams\shell\open\command" -Name "(Default)" -Value '"ms-teams.exe" "%1"' -PropertyType String -Force | Out-Null # Retrieve permissions for Teams directory $TeamsDirAcl= Get-Acl -Path "$TeamsDir" $TeamsDirSddl = $TeamsDirAcl.sddl $TeamsDirAcl.SetSecurityDescriptorSddlForm($TeamsDirSddl) # Create post-activation script to set permissions on Teams directory and register it $PostActScriptContent = @" `$Sddl = `'$TeamsDirSddl`' `$TeamsDir = "C:\Program Files\WindowsApps\" + (Get-ChildItem "C:\Program Files\WindowsApps\MSTeams*" -Directory | Sort-Object LastWriteTime | Select-Object -First 1).Name `$TeamsDirAcl = Get-Acl -Path "`$TeamsDir" `$TeamsDirAcl.SetSecurityDescriptorSddlForm(`$sddl) Set-Acl -Path "`$TeamsDir" -AclObject `$TeamsDirAcl Add-AppxPackage -DisableDevelopmentMode "`$TeamsDir\AppxManifest.xml" -Register Start-Process -FilePath "shell:appsFolder\MSTeams_8wekyb3d8bbwe!MSTeams" "@ $PostActScriptContent | Out-File "$env:USERPROFILE\Desktop\TeamsPostAct.ps1" -Encoding ASCII # Create post-deactivation script to remove Teams 'Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*MSTeams*" } | Remove-AppxPackage' | Out-File "$env:USERPROFILE\Desktop\TeamsPostDeact.ps1" # Grant permissions to Teams folder $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name TakeOwn /F $TeamsDir /A | Out-Null Icacls $TeamsDir /Grant $CurrentUser`:F | Out-Null # Disable automatic updates for Teams New-Item -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Force | Out-Null New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Teams" -Name "disableAutoUpdate" -Value "1" -PropertyType Dword -Force | Out-Null Rename-Item -Path "$TeamsDir\ms-teamsupdate.exe" -NewName "$TeamsDir\ms-teamsupdate.exe.bak" -Force # Restore permissions to Teams folder Set-Acl -Path "$TeamsDir" -AclObject $TeamsDirAcl # Display post-install instructions dialog Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName PresentationCore $window = New-Object System.Windows.Window $window.Title = "Next Steps" $window.Width = 400 $window.Height = 300 $window.WindowStartupLocation = 'CenterScreen' $window.SizeToContent = 'WidthAndHeight' $window.ResizeMode = 'NoResize' $stackPanel = New-Object System.Windows.Controls.StackPanel $stackPanel.Margin = '10' $textBlock = New-Object System.Windows.Controls.TextBlock $textBlock.Text = @" 1. Click 'Finish' to save the package 2. Playback the package 3. Set 'TeamsPostAct.ps1' as a post-activation script (saved to Desktop) 4. Set 'TeamsPostDeAct.ps1' as a post-eactivation script (saved to Desktop) 5. Save the package 6. (Optional) Edit the package metadata to set the icon to 'ms-teams.exe' "@ $textBlock.Margin = '0,0,0,20' $textBlock.TextWrapping = 'Wrap' $stackPanel.Children.Add($textBlock) $okButton = New-Object System.Windows.Controls.Button $okButton.Content = 'OK' $okButton.Width = 75 $okButton.Height = 30 $okButton.HorizontalAlignment = 'Center' $okButton.Add_Click({ $window.Close() }) $stackPanel.Children.Add($okButton) $window.Content = $stackPanel $window.ShowDialog()