-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractLanguages.ps1
297 lines (265 loc) · 9.25 KB
/
ExtractLanguages.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
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
param(
[parameter(Mandatory=$true,HelpMessage="Enter the path to the source directory for the CAB files")]
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string]$SourcePath,
[parameter(Mandatory=$true,HelpMessage="Enter the path to which the CAB files will be extracted")]
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string]$ExtractPath
)
Function Write-Log {
##########################################################################################################
<#
.SYNOPSIS
Log to a file in a format that can be read by Trace32.exe / CMTrace.exe
.DESCRIPTION
Write a line of data to a script log file in a format that can be parsed by Trace32.exe / CMTrace.exe
The severity of the logged line can be set as:
1 - Information
2 - Warning
3 - Error
Warnings will be highlighted in yellow. Errors are highlighted in red.
The tools to view the log:
CM Trace - Installation directory on Configuration Manager 2012 Site Server - <Install Directory>\tools\
.EXAMPLE
Write-Log c:\output\update.log "Application of MS15-031 failed" Apply_Patch 3
This will write a line to the update.log file in c:\output stating that "Application of MS15-031 failed".
The source component will be Apply_Patch and the line will be highlighted in red as it is an error
(severity - 3).
#>
##########################################################################################################
#Define and validate parameters
[CmdletBinding()]
Param(
#Path to the log file
[parameter(Mandatory=$True)]
[String]$LogFile,
#The information to log
[parameter(Mandatory=$True)]
[String]$Value,
#The source of the error
[parameter(Mandatory=$True)]
[String]$Component,
#The severity (1 - Information, 2- Warning, 3 - Error)
[parameter(Mandatory=$True)]
[ValidateRange(1,3)]
[Single]$Severity
)
#Obtain UTC offset
$DateTime = New-Object -ComObject WbemScripting.SWbemDateTime
$DateTime.SetVarDate($(Get-Date))
$UtcValue = $DateTime.Value
$UtcOffset = $UtcValue.Substring(21, $UtcValue.Length - 21)
#Create the line to be logged
$LogLine = "<![LOG[$Value]LOG]!>" +`
"<time=`"$(Get-Date -Format HH:mm:ss.fff)$($UtcOffset)`" " +`
"date=`"$(Get-Date -Format M-d-yyyy)`" " +`
"component=`"$Component`" " +`
"context=`"$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)`" " +`
"type=`"$Severity`" " +`
"thread=`"$($pid)`" " +`
"file=`"`">"
#Write the line to the passed log file
Out-File -InputObject $LogLine -Append -NoClobber -Encoding Default -FilePath $LogFile -WhatIf:$False
}
function CopyFiles{
param(
$pkgSourcePath,
$pkgDestPath
)
Write-Log $logfile "Extracting [$pack] pack for language [$lang] to [$pkgDestPath]" Extract 1
if(!(Test-Path $pkgDestPath)){
New-Item -ItemType Directory -Name $lang -Path $ExtractPath -Force
}
Copy-Item $pkgSourcePath $pkgDestPath
}
#Sanitize inputs
if($ExtractPath.Substring($ExtractPath.Length-1) -eq '\'){
$ExtractPath = $ExtractPath.Substring(0,$ExtractPath.Length-1)
}
if($SourcePath.Substring($SourcePath.Length-1) -eq '\'){
$SourcePath = $SourcePath.Substring(0,$SourcePath.Length-1)
}
$logfile = 'C:\Windows\Temp\Extract-Languages.log'
if(!(Test-Path $logfile)){
New-Item -ItemType File -Path $logfile -Force
}
$FontMapping = @{
'Ethi'=@('am-ET','ti-ET')
'Arab'=@('ar-SA','fa-IR','ku-Arab-IQ','pa-Arab-PK','prs-AF','sd-Arab-PK','ug-CN','ur-PK')
'Syrc'=@('ar-SY','syr-SY')
'Beng'=@('as-IN','bn-BD','bn-IN')
'Cher'='chr-Cher-US'
'Gujr'='gu-IN'
'Hebr'='he-IL'
'Deva'=@('hi-IN','kok-IN','mr-IN','ne-NP')
'Jpan'='ja-JP'
'Khmr'='km-KH'
'Knda'='kn-IN'
'Kore'='ko-KR'
'Laoo'='lo-LA'
'Mlym'='ml-IN'
'Orya'='or-IN'
'Guru'='pa-IN'
'Sinh'='si-LK'
'Taml'='ta-IN'
'Telu'='te-IN'
'Thai'='th-TH'
'Hans'='zh-CN'
'Hant'='zh-TW'
}
$SupportedLanguages=@{
'af-za'=$false
'ar-eg'=$true
'ar-sa'=$true
'as-in'=$false
'az-latn-az'=$false
'ba-ru'=$false
'be-by'=$false
'bg-bg'=$true
'bn-bd'=$false
'bn-in'=$false
'bs-latn-ba'=$false
'ca-es'=$true
'cs-cz'=$true
'cy-gb'=$false
'da-dk'=$true
'de-at'=$true
'de-ch'=$true
'de-de'=$true
'el-gr'=$true
'en-au'=$true
'en-ca'=$true
'en-gb'=$true
'en-ie'=$true
'en-in'=$true
'en-us'=$true
'es-es'=$true
'es-mx'=$true
'et-ee'=$true
'eu-es'=$false
'fa-ir'=$false
'fi-fi'=$true
'fil-ph'=$true
'fr-ca'=$true
'fr-ch'=$true
'fr-fr'=$true
'ga-ie'=$false
'gd-gb'=$false
'gl-es'=$false
'gu-in'=$false
'ha-latn-ng'=$false
'haw-us'=$false
'he-il'=$true
'hi-in'=$false
'hr-hr'=$true
'hu-hu'=$true
'hy-am'=$false
'id-id'=$false
'ig-ng'=$false
'is-is'=$true
'it-it'=$true
'ja-jp'=$true
'ka-ge'=$false
'kk-kz'=$false
'kl-gl'=$false
'kn-in'=$false
'kok-deva-in'=$false
'ko-kr'=$true
'ky-kg'=$false
'lb-lu'=$false
'lt-lt'=$true
'lv-lv'=$true
'mi-nz'=$false
'mk-mk'=$false
'ml-in'=$false
'mn-mn'=$false
'mr-in'=$false
'ms-bn'=$true
'ms-my'=$true
'mt-mt'=$false
'nb-no'=$true
'ne-np'=$false
'nl-be'=$true
'nl-nl'=$true
'nn-no'=$true
'nso-za'=$false
'or-in'=$false
'pa-in'=$false
'pl-pl'=$true
'ps-af'=$false
'pt-br'=$true
'pt-pt'=$true
'rm-ch'=$false
'ro-ro'=$true
'ru-ru'=$true
'rw-rw'=$false
'sah-ru'=$false
'si-lk'=$false
'sk-sk'=$false
'sl-si'=$true
'sq-al'=$false
'sr-cyrl-rs'=$false
'sr-latn-rs'=$false
'sv-se'=$true
'sw-ke'=$false
'ta-in'=$false
'te-in'=$false
'tg-cyrl-tj'=$false
'th-th'=$true
'tk-tm'=$false
'tn-za'=$false
'tr-tr'=$true
'tt-ru'=$false
'ug-cn'=$false
'uk-ua'=$true
'ur-pk'=$false
'uz-latn-uz'=$false
'vi-vn'=$true
'wo-sn'=$false
'xh-za'=$false
'yo-ng'=$false
'zh-cn'=$true
'zh-hk'=$true
'zh-tw'=$true
'zu-za'=$false
}
Write-Log $logfile "Starting execution of Extract-Languages.ps1" Start 1
#Gather packages
Write-Log $logfile "Gathering Language Feature CAB files from [$SourcePath]" Gather 1
$TODOpkgs = Get-ChildItem $SourcePath -Filter '*LanguageFeatures*.cab'
if($TODOpkgs){
Write-Log $logfile "The following packages will be extracted:" Gather 1
foreach($pkg in $TODOpkgs){
Write-Log $logfile $pkg.Name Gather 1
}
foreach($pkg in $TODOpkgs){
#Extract packages
if($pkg.Name -match 'LanguageFeatures-(?<Pack>[A-Z]*(?=-))-((?<lang>.*)(?=-Package))'){
$pack = $matches['Pack']
$lang = $matches['lang']
if($pack -eq 'Fonts'){
Write-Log $logfile "Found [$lang] Font pack, mapped to languages [$($FontMapping.$lang -join ',')]" Extract 1
foreach($l in $FontMapping.$lang){
if($SupportedLanguages.$l){
CopyFiles $pkg.FullName "$ExtractPath\$l"
}
else {
Write-Log $logfile "[$lang] Font pack maps to [$l], which is not a supported language. Skipping copy for [$l]." Extract 1
}
}
}
else {
if($SupportedLanguages.$lang){
CopyFiles $pkg.FullName "$ExtractPath\$lang"
}
else {
Write-Log $logfile "[$lang] is not a supported language. Skipping [$pack] pack for [$lang]" Extract 1
}
}
} else {
Write-Log $logfile "Package [$($pkg.Name)] was queued but does not appear to be a Language Feature. Skipping package." Extract 2
}
}
} else {
Write-Log $logfile "No packages found. Nothing to do." Gather 2
}