-
Notifications
You must be signed in to change notification settings - Fork 0
/
DK_Teams_MSI_update.ps1
121 lines (84 loc) · 2.97 KB
/
DK_Teams_MSI_update.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#DK Teams MSI update
# the url for the download
$DLURL = "https://aka.ms/teams64bitmsi"
# the temp folder name for the download and the install to run from
$temp = "temp"
# the nice name of the item you are downloading
$name = "Teams Machine Wide MSI"
# the actual msi name (you dont need to add .msi)
$msi = "teams64bitmsi"
# function to check if temp exists if not make it
function temp-check{
if (-not (Test-Path $Env:SystemDrive\$temp))
{
New-Item -ItemType Directory $Env:SystemDrive\$temp | out-null
}
}
# function do the download
function Download{
# enable TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-host "Downloading $name"
temp-check
# Download it
Invoke-WebRequest -Uri $DLURL -OutFile "$Env:SystemDrive\$temp\$msi.msi"
Write-host "$name is downloaded"
}
# Function to do the install
function install-TeamsMSI{
Write-host "Installing $name"
Start-Process msiexec.exe -Wait -ArgumentList "/i", "$Env:SystemDrive\$temp\$msi.msi", "ALLUSERS=1", "/qn", "/norestart" -WindowStyle Hidden
Write-host "$name Should now be installed"
}
#function to find the users and nuke out old teams to force them to be updated
function AllUsers-Teams-Nuke{
# Already existing user AppData Teams loop
# Defines the location of Teams App Data
$Teams_users_appdata = "\AppData\Local\Microsoft\Teams"
# get the users minus Default and Administrator and Public
$list_of_users = Get-ChildItem -Path $Env:SystemDrive\Users | Where-Object {($_.Name -notlike "Public") -and ($_.Name -notlike "Administrator") -and ($_.Name -notlike "Default")}
# loop for each user found
Foreach ($user in $list_of_users)
{
# check if the folder exists already
if (Test-Path "$($user.FullName)$($Teams_users_appdata)")
# if found nuke the teams folder
{
write-host "Found $($user.FullName)$($Teams_users_appdata)"
Write-host "Nuking old Teams Install for $user"
Remove-Item "$($user.FullName)$($Teams_users_appdata)" -Force -Recurse -ErrorAction silentlycontinue
}
else
{
Write-host "No action needed for $user"
}
}
}
# check for old Teams MSI and nuke it
function Nuke-old-Teams{
$TeamsFinder = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty | Where-Object {$_.DisplayName -eq "Teams Machine-Wide Installer" } | Select-Object -Property DisplayName, pschildname
if (-not($TeamsFinder))
{
write-host "$name NOT found"
}else{
write-host "Found old $name"
write-host "Nuking old $name"
If ($TeamsFinder.PSChildName)
{
$Teams_MSI_Nuke = $TeamsFinder.PSChildName
start-Process msiexec.exe -ArgumentList "/x", "$Teams_MSI_Nuke", "/qn", "/norestart" -WindowStyle Hidden -wait
}
write-host "$name Nuke Completed"
}
}
#kill Teams if users have it open
Function kill-running-teams{
Get-Process | Where {$_.Description -eq "Microsoft Teams"} | Stop-Process -force
}
#run it
Download
Nuke-old-Teams
kill-running-teams
AllUsers-Teams-Nuke
install-TeamsMSI