-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathDownload.ps1
More file actions
347 lines (309 loc) · 11 KB
/
Download.ps1
File metadata and controls
347 lines (309 loc) · 11 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<#
.SYNOPSIS
Download Office 2019, 2021, 2024, and 365
.PARAMETER Branch
Choose Office branch: 2019, 2021, 2024, and 365
.PARAMETER Channel
Choose Office channel: 2019, 2021, 2024, and 365
.PARAMETER Components
Choose Office components: Access, OneDrive, Outlook, Word, Excel, PowerPoint, Teams, OneNote, Publisher, Project 2019/2021/2024
.EXAMPLE Download Office 2019 with the Word, Excel, PowerPoint components
Download.ps1 -Branch ProPlus2019Retail -Channel Current -Components Word, Excel, PowerPoint
.EXAMPLE Download Office 2021 with the Excel, Word components
Download.ps1 -Branch ProPlus2021Volume -Channel PerpetualVL2021 -Components Excel, Word
.EXAMPLE Download Office 2024 with the Excel, Word components
Download.ps1 -Branch ProPlus2024Volume -Channel PerpetualVL2024 -Components Excel, Word
.EXAMPLE Download Office 365 with the Excel, Word, PowerPoint components
Download.ps1 -Branch O365ProPlusRetail -Channel Current -Components Excel, OneDrive, Outlook, PowerPoint, Teams, Word
.LINK
https://config.office.com/deploymentsettings
.LINK
https://docs.microsoft.com/en-us/deployoffice/vlactivation/gvlks
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet("ProPlus2019Retail", "ProPlus2021Volume", "ProPlus2024Volume", "O365ProPlusRetail")]
[string]
$Branch,
[Parameter(Mandatory = $true)]
[ValidateSet("Current", "PerpetualVL2021", "PerpetualVL2024", "SemiAnnual")]
[string]
$Channel,
[Parameter(Mandatory = $true)]
[ValidateSet("Access", "OneDrive", "Outlook", "Word", "Excel", "OneNote", "Publisher", "PowerPoint", "Teams", "ProjectPro2019Volume", "ProjectPro2021Volume", "ProjectPro2024Volume")]
[string[]]
$Components
)
if (-not (Test-Path -Path "$PSScriptRoot\Default.xml"))
{
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "Default.xml doesn't exist"
exit
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($Host.Version.Major -eq 5)
{
# Progress bar can significantly impact cmdlet performance
# https://github.com/PowerShell/PowerShell/issues/2138
$Script:ProgressPreference = "SilentlyContinue"
}
[xml]$Config = Get-Content -Path "$PSScriptRoot\Default.xml" -Encoding Default -Force
switch ($Branch)
{
ProPlus2019Retail
{
($Config.Configuration.Add.Product | Where-Object -FilterScript {$_.ID -eq ""}).ID = "ProPlus2019Retail"
}
ProPlus2021Volume
{
($Config.Configuration.Add.Product | Where-Object -FilterScript {$_.ID -eq ""}).ID = "ProPlus2021Volume"
}
ProPlus2024Volume
{
($Config.Configuration.Add.Product | Where-Object -FilterScript {$_.ID -eq ""}).ID = "ProPlus2024Volume"
}
O365ProPlusRetail
{
($Config.Configuration.Add.Product | Where-Object -FilterScript {$_.ID -eq ""}).ID = "O365ProPlusRetail"
}
}
switch ($Channel)
{
Current
{
($Config.Configuration.Add | Where-Object -FilterScript {$_.Channel -eq ""}).Channel = "Current"
}
PerpetualVL2021
{
($Config.Configuration.Add | Where-Object -FilterScript {$_.Channel -eq ""}).Channel = "PerpetualVL2021"
}
PerpetualVL2024
{
($Config.Configuration.Add | Where-Object -FilterScript {$_.Channel -eq ""}).Channel = "PerpetualVL2024"
}
SemiAnnual
{
($Config.Configuration.Add | Where-Object -FilterScript {$_.Channel -eq ""}).Channel = "SemiAnnual"
}
}
foreach ($Component in $Components)
{
switch ($Component)
{
Access
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='Access']")
$Node.ParentNode.RemoveChild($Node)
}
Excel
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='Excel']")
$Node.ParentNode.RemoveChild($Node)
}
OneDrive
{
$OneDrive = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if (-not $OneDrive)
{
switch ((Get-CimInstance -ClassName Win32_OperatingSystem).Caption)
{
{$_ -match 10}
{
if (Test-Path -Path $env:SystemRoot\SysWOW64\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "OneDrive Installing" -Verbose
Start-Process -FilePath $env:SystemRoot\SysWOW64\OneDriveSetup.exe
}
else
{
$Script:OneDriveInstalled = $false
}
}
{$_ -match 11}
{
if (Test-Path -Path $env:SystemRoot\System32\OneDriveSetup.exe)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "OneDrive Installing" -Verbose
Start-Process -FilePath $env:SystemRoot\System32\OneDriveSetup.exe
}
else
{
$Script:OneDriveInstalled = $false
}
}
}
if (-not $Script:OneDriveInstalled)
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "OneDrive Downloading" -Verbose
try
{
# Parse XML to get the URL
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @{
Uri = "https://g.live.com/1rewlive5skydrive/OneDriveProductionV2"
UseBasicParsing = $true
Verbose = $true
}
$Content = Invoke-RestMethod @Parameters
}
catch [System.Net.WebException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Connection could not be established with https://oneclient.sfx.ms" -Verbose
exit
}
# Remove invalid chars
[xml]$OneDriveXML = $Content -replace "", ""
$OneDriveURL = ($OneDriveXML).root.update.amd64binary.url | Select-Object -Index 1
try
{
$Parameters = @{
Uri = $OneDriveURL
OutFile = "$PSScriptRoot\OneDriveSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Connection could not be established with https://oneclient.sfx.ms" -Verbose
exit
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "OneDrive was downloaded to $PSScriptRoot" -Verbose
}
}
}
Outlook
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='Outlook']")
$Node.ParentNode.RemoveChild($Node)
}
Word
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='Word']")
$Node.ParentNode.RemoveChild($Node)
}
PowerPoint
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='PowerPoint']")
$Node.ParentNode.RemoveChild($Node)
}
OneNote
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='OneNote']")
$Node.ParentNode.RemoveChild($Node)
}
Publisher
{
$Node = $Config.SelectSingleNode("//ExcludeApp[@ID='Publisher']")
$Node.ParentNode.RemoveChild($Node)
}
Teams
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Teams Downloading" -Verbose
try
{
# https://www.microsoft.com/microsoft-teams/download-app
$Parameters = @{
Uri = "https://statics.teams.cdn.office.net/evergreen-assets/DesktopClient/MSTeamsSetup.exe"
OutFile = "$PSScriptRoot\MSTeamsSetup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-RestMethod @Parameters
}
catch [System.Net.WebException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Connection could not be established with https://statics.teams.cdn.office.net" -Verbose
exit
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Teams was downloaded to $PSScriptRoot" -Verbose
}
ProjectPro2019Volume
{
$ProjectNode = $Config.Configuration.Add.AppendChild($Config.CreateElement("Product"))
$ProjectNode.SetAttribute("ID","ProjectPro2019Volume")
$ProjectElement = $ProjectNode.AppendChild($Config.CreateElement("Language"))
$ProjectElement.SetAttribute("ID","MatchOS")
}
ProjectPro2021Volume
{
$ProjectNode = $Config.Configuration.Add.AppendChild($Config.CreateElement("Product"))
$ProjectNode.SetAttribute("ID","ProjectPro2021Volume")
$ProjectElement = $ProjectNode.AppendChild($Config.CreateElement("Language"))
$ProjectElement.SetAttribute("ID","MatchOS")
}
ProjectPro2024Volume
{
$ProjectNode = $Config.Configuration.Add.AppendChild($Config.CreateElement("Product"))
$ProjectNode.SetAttribute("ID","ProjectPro2024Volume")
$ProjectElement = $ProjectNode.AppendChild($Config.CreateElement("Language"))
$ProjectElement.SetAttribute("ID","MatchOS")
}
}
}
$Config.Save("$PSScriptRoot\Config.xml")
# Microsoft blocks Russian and Belarusian regions for Office downloading
# https://docs.microsoft.com/en-us/windows/win32/intl/table-of-geographical-locations
# https://en.wikipedia.org/wiki/2022_Russian_invasion_of_Ukraine
if (((Get-WinHomeLocation).GeoId -eq "203") -or ((Get-WinHomeLocation).GeoId -eq "29"))
{
# Set to Ukraine
$Script:Region = (Get-WinHomeLocation).GeoId
Set-WinHomeLocation -GeoId 241
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "Region changed to Ukrainian"
$Script:RegionChanged = $true
}
# It is needed to remove these keys to bypass Russian and Belarusian region blocks
$Paths = @(
"HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Experiment",
"HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\ExperimentConfigs",
"HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\ExperimentEcs"
)
Remove-Item -Path $Paths -Recurse -Force -ErrorAction Ignore
# Download Office Deployment Tool
# https://www.microsoft.com/en-us/download/details.aspx?id=49117
if (-not (Test-Path -Path "$PSScriptRoot\setup.exe"))
{
try
{
$Parameters = @{
Uri = "https://officecdn.microsoft.com/pr/wsus/setup.exe"
OutFile = "$PSScriptRoot\setup.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Connection could not be established with https://officecdn.microsoft.com" -Verbose
exit
}
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Downloading... Please do not close any console windows." -Verbose
# Start downloading to the Office folder
Start-Process -FilePath "$PSScriptRoot\setup.exe" -ArgumentList "/download `"$PSScriptRoot\Config.xml`"" -Wait
if ($Script:RegionChanged)
{
# Set to original region ID
Set-WinHomeLocation -GeoId $Script:Region
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "Region changed to original one"
}
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "Office downloaded. Please run Install.ps1 file with administrator privileges." -Verbose