-
Notifications
You must be signed in to change notification settings - Fork 15
/
psMacUpdatesOFFICE.ps1
257 lines (217 loc) · 9.36 KB
/
psMacUpdatesOFFICE.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
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
<#
.Synopsis
Download MAU update for mac
.DESCRIPTION
Authors - Adam Martin, David Coupe
Based on Bash script by [email protected]
Needs to run as administrator to allow file rights
Creates directory structure for IIS
Downloads updates to temporary structure
Deletes original files from IIS
moves new downloads to IIS structure
.PARAMETER Channel
Must supply channel. Values acceptable are "Production", "External", "InsiderFast"
.PARAMETER IISRoot
Must supply iisBase. The path to default IIS eg C:\inetpub\wwwroot
.PARAMETER IisFolder
Must supply channel. The Folder name of the Share to publish in iis. Eg MAUCache
.PARAMETER Channel
Must supply TempShare. Path For working folder. Everything is downloaded then moved from this location. Eg c:\temp
.EXAMPLE
powershell.exe .\psMacUpdatesOFFICE.ps1 -channel Production -IISRoot C:\inetpub\wwwroot -IisFolder maucache -TempShare C:\temp
.EXAMPLE
powershell.exe .\psMacUpdatesOFFICE.ps1 -channel Production -IISRoot C:\inetpub\wwwroot -IisFolder maucache -TempShare C:\temp -verbose
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$true,HelpMessage='Must supply channel. Values acceptable are "Production", "External", "InsiderFast"')]
[ValidateSet("Production", "External", "InsiderFast")]
[string]
$channel,
[Parameter(Mandatory=$true,HelpMessage='Default IIS LOcation EG c:\iinetpub\wwwroot')]
[Validatescript({if (test-path ($_)){$true} Else {Throw "$_ doesnt exist. Must be a valid Path"}})]
[string]
$IISRoot,
[Parameter(Mandatory=$true,HelpMessage='IIS Shared Folder Name. Also used in the temp folder eg. MAUCache')]
[string]
$IisFolder,
[Parameter(Mandatory=$true,HelpMessage='Path to Temp working space eg c:\temp')]
[Validatescript({if (test-path ($_)){$true} Else {Throw "$_ doesnt exist. Must be a valid Path"}})]
[string]
$TempShare
)
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator'))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Break
}
$null = New-Object System.Net.webclient
#$PublishFolderName = "MAUCache"
#$publishBasePath = "C:\inetpub\wwwroot"
#$tempfolderLocation = "C:\temp"
$PublishFolderName = $IisFolder
$publishBasePath = $IISRoot
$tempfolderLocation = $TempShare
#Test iis shared folder exists if not make it
if (!(test-path "$publishBasePath\$PublishFolderName")){
New-Item -ItemType Directory -Path "$publishBasePath" -Name "$PublishFolderName"
}
$PublishFolder = "$publishBasePath\$PublishFolderName"
$tempFolder = "$tempfolderLocation\$PublishFolderName"
$collarteralFolder = $tempFolder
#setup TEmp environment
If (Test-path -Path $tempFolder)
{
Remove-Item $tempfolder -Recurse -Force
}
#Create TEmp Structure
New-Item -ItemType Directory -Path $tempfolderlocation -Name "$PublishFolderName"
New-Item -ItemType Directory -Path "$tempfolder" -Name "Collateral"
$starturl = "https://officecdn-microsoft-com.akamaized.net"
switch ($channel)
{
"Production"{$webUrlDownload = "$starturl/pr/C1297A47-86C4-4C1F-97FA-950631F94777/MacAutoupdate/"}
"External"{$webUrlDownload = "$starturl/pr/1ac37578-5a24-40fb-892e-b89d85b6dfaa/MacAutoupdate/"}
"InsiderFast"{$webUrlDownload = "$starturl/pr/4B2D7701-0A4F-49C8-B4CB-0C2D4043F51F/MacAutoupdate/"}
}
[io.file]::WriteAllbytes("$collarteralFolder\builds.txt",(Invoke-WebRequest -URI "$webUrlDownload/builds.txt").content)
#compare temp build.txt with prod build.txt
#Initalise $origcontent array in case of first run
#if change detected then continue else stop
$origContent = @("")
if (test-path "$PublishFolder\builds.txt"){$origContent = Get-Content "$PublishFolder\builds.txt"}
$newContent = Get-Content "$collarteralFolder\builds.txt"
If ((compare-object $origContent $newContent).count -eq 0){
Write-Verbose "No Change"
Break
}
$MAUID_MAU3X="0409MSAU03"
$MAUID_MAU4X="0409MSAU04"
$MAUID_WORD2019="0409MSWD2019"
$MAUID_EXCEL2019="0409XCEL2019"
$MAUID_POWERPOINT2019="0409PPT32019"
$MAUID_OUTLOOK2019="0409OPIM2019"
$MAUID_ONENOTE2019="0409ONMC2019"
$MAUID_WORD2016="0409MSWD15"
$MAUID_EXCEL2016="0409XCEL15"
$MAUID_POWERPOINT2016="0409PPT315"
$MAUID_OUTLOOK2016="0409OPIM15"
$MAUID_ONENOTE2016="0409ONMC15"
$MAUID_OFFICE2011="0409MSOF14"
$MAUID_LYNC2011="0409UCCP14"
$MAUID_SKYPE2016="0409MSFB16"
$MAUID_INTUNECP="0409IMCP01"
$MAUID_REMOTEDESKTOP10="0409MSRD10"
function BuildApplicationArray() {
# Builds an array of all the MAU-enabled applications that we care about
$MAUAPP=@()
$MAUAPP+="$MAUID_MAU3X"
$MAUAPP+="$MAUID_MAU4X"
$MAUAPP+="$MAUID_WORD2019"
$MAUAPP+="$MAUID_EXCEL2019"
$MAUAPP+="$MAUID_POWERPOINT2019"
$MAUAPP+="$MAUID_OUTLOOK2019"
$MAUAPP+="$MAUID_ONENOTE2019"
$MAUAPP+="$MAUID_WORD2016"
$MAUAPP+="$MAUID_EXCEL2016"
$MAUAPP+="$MAUID_POWERPOINT2016"
$MAUAPP+="$MAUID_OUTLOOK2016"
$MAUAPP+="$MAUID_ONENOTE2016"
$MAUAPP+="$MAUID_OFFICE2011"
$MAUAPP+="$MAUID_LYNC2011"
$MAUAPP+="$MAUID_SKYPE2016"
$MAUAPP+="$MAUID_INTUNECP"
$MAUAPP+="$MAUID_REMOTEDESKTOP10"
return $MAUAPP
}
function DownloadUPdate ([Parameter(Mandatory=$true)]$Payload, [Parameter(Mandatory=$true)]$location)
{
#Test-WritePath
Write-Verbose "Starting $location - $collateral\$payload"
#DOwnload to correct path
#TEST BASELINE
$collateral = "$collarteralFolder"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($($location), "$collateral\$payload")
}
function DownloadCollateralFiles ([Parameter(Mandatory=$true)]$downloadarray,[Parameter(Mandatory=$true)]$weburldown){
# Downloads XML/CAT collateral files
foreach ($Down in $DownloadArray){
$payload =""
$locationstring = ""
$UpdateVersions = ""
Write-Verbose "$down"
[io.file]::WriteAllbytes("$collarteralFolder\$down.xml",(Invoke-WebRequest -URI "$weburldown$down.xml").content)
[io.file]::WriteAllbytes("$collarteralFolder\$down-chk.xml",(Invoke-WebRequest -URI "$weburldown$down-chk.xml").content)
[io.file]::WriteAllbytes("$collarteralFolder\$down.cat",(Invoke-WebRequest -URI "$weburldown$down.cat").content)
#get xml and find updateversion
$log = "$collarteralFolder\$down.xml"
$collateral = $collarteralFolder
$patt = "<key>Update Version"
$indx = Select-String $patt $log | ForEach-Object {$_.LineNumber}
if ($indx.count -ge 2){
$UpdateVersions= @((Get-Content $log)[$indx])
$UpdateVersions=$UpdateVersions -replace "</String>", ""
$UpdateVersions=$UpdateVersions -replace "<String>", ""
$UpdateVersions=$UpdateVersions.trim()
$pathtoput = "$($updateversions[0])"
}
elseif ($indx.count -eq 1){
$UpdateVersions= @((Get-Content $log)[$indx])
$UpdateVersions=$UpdateVersions -replace "</String>", ""
$UpdateVersions=$UpdateVersions -replace "<String>", ""
$UpdateVersions=$UpdateVersions.trim()
$pathtoput="$($UpdateVersions)"
}
else {
$pathtoput="Legacy"
}
#TEST COLLATERAL PATH EXISTS
if (!(Test-Path "$collateral\$pathtoput")){
new-item -ItemType Directory -Path $collateral -Name $pathtoput -Verbose
}
write-verbose "$collateral\$pathtoput\$down.xml"
Copy-Item -Path "$collarteralFolder\$down.xml" -Destination "$collateral\$pathtoput\$down.xml" -Verbose
Copy-Item -Path "$collarteralFolder\$down-chk.xml" -Destination "$collateral\$pathtoput\$down-chk.xml" -Verbose
Copy-Item -Path "$collarteralFolder\$down.cat" -Destination "$collateral\$pathtoput\$down.cat" -Verbose
#PAYLOAD NAME
$log = "$collarteralFolder\$down.xml"
$patt = "<KEY>Payload"
$indxp = Select-String $patt $log | ForEach-Object {$_.LineNumber}
write-verbose "$indx $($down)"
$payload=@((Get-Content $log)[$indxp])
$payload=$payload -replace "</String>", ""
$payload=$payload -replace "<String>", ""
$payload=$payload.trim()
#DOWNLOAD FILE
$patt = "<KEY>Location"
$indx = Select-String $patt $log | ForEach-Object {$_.LineNumber}
$locationstring= @((Get-Content $log)[$indx])
$locationstring=$locationstring -replace "</String>", ""
$locationstring=$locationstring -replace "<String>", ""
$locationstring=$locationstring.trim()
if ($indxp.count -le 1){
write-verbose "One Detected $payload $locationstring"
DownloadUPdate -Payload $payload -location $locationstring
}
else
{
for ($x = 0; $x -le ($($indxp.count)-1); $x += 1)
{
write-verbose "One Detected $x"
$pay = $($payload[$x])
$loc = $($locationstring[$x])
DownloadUPdate -Payload $pay -location $loc
}
}
}
}
$mauApp = BuildApplicationArray
DownloadCollateralFiles -downloadarray $mauApp -weburldown $webUrlDownload
#rename Folders
#Sanity check of folder before renaming
if ((Get-ChildItem $tempfolder).count -ge 10){
Remove-Item $PublishFolder -recurse -Force
start-sleep -Seconds 30
Move-Item -Path $tempfolder -Destination "$publishBasePath"
}