@@ -45,7 +45,7 @@ Function Add-TextToCMLog {
45
45
# #########################################################################################################
46
46
<#
47
47
. SYNOPSIS
48
- Log to a file in a format that can be read by Trace32.exe / CMTrace.exe
48
+ Log to a file in a format that can be read by Trace32.exe / CMTrace.exe
49
49
50
50
. DESCRIPTION
51
51
Write a line of data to a script log file in a format that can be parsed by Trace32.exe / CMTrace.exe
@@ -67,7 +67,7 @@ Function Add-TextToCMLog {
67
67
Add-TextToCMLog c:\output\update.log "Application of MS15-031 failed" Apply_Patch 3
68
68
69
69
This will write a line to the update.log file in c:\output stating that "Application of MS15-031 failed".
70
- The source component will be Apply_Patch and the line will be highlighted in red as it is an error
70
+ The source component will be Apply_Patch and the line will be highlighted in red as it is an error
71
71
(severity - 3).
72
72
73
73
#>
96
96
97
97
98
98
# Obtain UTC offset
99
- $DateTime = New-Object - ComObject WbemScripting.SWbemDateTime
99
+ $DateTime = New-Object - ComObject WbemScripting.SWbemDateTime
100
100
$DateTime.SetVarDate ($ (Get-Date ))
101
101
$UtcValue = $DateTime.Value
102
102
$UtcOffset = $UtcValue.Substring (21 , $UtcValue.Length - 21 )
@@ -148,7 +148,7 @@ ForEach ($status in $SyncStatus){
148
148
' WSUSServerName' = $status.WSUSServerName ;
149
149
' WSUSSourceServer' = $status.WSUSSourceServer }
150
150
151
- $Results += New-Object – TypeName PSObject – Prop $properties
151
+ $Results += New-Object � TypeName PSObject � Prop $properties
152
152
}
153
153
154
154
@@ -180,24 +180,37 @@ Function Invoke-SyncCheck {
180
180
181
181
$WaitInterval = 0 # Used to skip the initial wait cycle if it isn't necessary.
182
182
Do {
183
-
183
+
184
184
# Wait until the loop has iterated once.
185
185
If ($WaitInterval -gt 0 ){
186
186
Add-TextToCMLog $LogFile " Waiting $TimeToWait minutes for lead time to pass before executing." $component 1
187
- Start-Sleep - Seconds ($WaitInterval )
188
- }
187
+ Start-Sleep - Seconds ($WaitInterval )
188
+ }
189
189
190
190
# Loop through each SUP and wait until they are all done syncing.
191
191
Do {
192
192
# If syncronizing then wait.
193
193
If ($Syncronizing ){
194
- Add-TextToCMLog $LogFile " Waiting for software update points to stop syncing." $component 1
195
- Start-Sleep - Seconds (300 )
194
+ Add-TextToCMLog $LogFile " Waiting for software update points to stop syncing." $component 1
195
+ Start-Sleep - Seconds (300 )
196
196
}
197
197
198
+ <#
199
+ Source: http://eskonr.com/2015/01/download-sccm-configmgr-2012-r2-cu3-status-messages-documentation/
200
+ 6701 = WSUS Synchronization started.
201
+ 6702 = WSUS Synchronization done.
202
+ 6703 = WSUS Synchronization failed.
203
+ 6704 = WSUS Synchronization in progress. Current phase: Synchronizing WSUS Server.
204
+ 6705 = WSUS Synchronization in progress. Current phase: Synchronizing site database.
205
+ 6706 = WSUS Synchronization in progress. Current phase: Synchronizing Internet facing WSUS Server.
206
+ 6707 = Content of WSUS Server %1 is out of sync with upstream server %2.
207
+ 6708 = WSUS synchronization complete, with pending license terms downloads.
208
+ #>
209
+ $SynchronizingStatusMessages = @ (6701 , 6704 , 6705 , 6706 )
210
+
198
211
$Syncronizing = $False
199
212
ForEach ($softwareUpdatePointSyncStatus in Get-CMSoftwareUpdateSyncStatus ){
200
- If ($softwareUpdatePointSyncStatus.LastSyncState -eq 6704 ){$Syncronizing = $True }
213
+ If ($softwareUpdatePointSyncStatus.LastSyncState -in $SynchronizingStatusMessages ){$Syncronizing = $True }
201
214
}
202
215
} Until (! $Syncronizing )
203
216
@@ -215,7 +228,7 @@ Function Invoke-SyncCheck {
215
228
}
216
229
}
217
230
218
-
231
+
219
232
# Calculate the remaining time to wait for the lead time to expire.
220
233
$TimeToWait = ($syncTimeStamp.AddMinutes ($SyncLeadTime ) - (Get-Date )).Minutes
221
234
@@ -274,14 +287,14 @@ Function Get-SiteCode {
274
287
}
275
288
276
289
# If PSDrive exists then get the site code from it. Otherwise, try to create the drive.
277
- If ($PSDriveExists ) {
290
+ If ($PSDriveExists ) {
278
291
$SiteCode = Get-PSDrive - PSProvider CMSite
279
292
} Else {
280
293
# Try to determine the site code if none was passed in.
281
294
If (-Not ($SiteCode ) ) {
282
295
If (Test-RegistryValue - Path " HKLM:\SOFTWARE\Microsoft\SMS\Identification" - Value " Site Code" ){
283
296
$SiteCode = Get-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\SMS\Identification" | Select-Object - ExpandProperty " Site Code"
284
- } ElseIf (Test-RegistryValue - Path " HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client" - Value " AssignedSiteCode" ) {
297
+ } ElseIf (Test-RegistryValue - Path " HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client" - Value " AssignedSiteCode" ) {
285
298
$SiteCode = Get-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client" | Select-Object - ExpandProperty " AssignedSiteCode"
286
299
} Else {
287
300
Return
@@ -303,7 +316,7 @@ $LogFile = "filesystem::$($LogFile)"
303
316
$component = (Split-Path $PSCommandPath - Leaf).Replace(" .ps1" , " " )
304
317
305
318
# If the log file exists and is larger then the maximum then roll it over.
306
- If (Test-path $LogFile - PathType Leaf) {
319
+ If (Test-path $LogFile - PathType Leaf) {
307
320
If ((Get-Item $LogFile ).length -gt $MaxLogSize ){
308
321
Move-Item - Force $LogFile ($LogFile -replace " .$" , " _" ) - WhatIf:$False
309
322
}
@@ -323,7 +336,7 @@ If (Test-Path -Path $lastRanPath -NewerThan ((get-date).AddHours(-24).ToString()
323
336
}
324
337
325
338
# Make sure the last Patch Tuesday was less than a week away.
326
- If ($WeekOfPatchTuesday ){
339
+ If ($WeekOfPatchTuesday ){
327
340
# Care of: http://www.madwithpowershell.com/2014/10/calculating-patch-tuesday-with.html
328
341
$BaseDate = ( Get-Date - Day 12 ).Date
329
342
$PatchTuesday = $BaseDate.AddDays ( 2 - [int ]$BaseDate.DayOfWeek )
@@ -362,11 +375,11 @@ If (!$SiteCode){$SiteCode = Get-SiteCode}
362
375
If (! (Test-Path " $ ( $SiteCode ) :" )) {
363
376
Try {
364
377
Add-TextToCMLog $LogFile " Trying to create the PS Drive $ ( $SiteCode ) " $component 1
365
- New-PSDrive - Name $SiteCode - PSProvider CMSite - Root " ." - WhatIf:$False | Out-Null
378
+ New-PSDrive - Name $SiteCode - PSProvider CMSite - Root " ." - WhatIf:$False | Out-Null
366
379
} Catch {
367
380
Add-TextToCMLog $LogFile " The site's PS drive doesn't exist nor could it be created." $component 3
368
381
Add-TextToCMLog $LogFile " Error: $ ( $_.Exception.Message ) " $component 3
369
- Add-TextToCMLog $LogFile " $ ( $_.InvocationInfo.PositionMessage ) " $component 3
382
+ Add-TextToCMLog $LogFile " $ ( $_.InvocationInfo.PositionMessage ) " $component 3
370
383
Return
371
384
}
372
385
}
@@ -376,7 +389,7 @@ $OriginalLocation = Get-Location
376
389
377
390
# Set and verify the location.
378
391
Try {
379
- Add-TextToCMLog $LogFile " Connecting to site: $ ( $SiteCode ) " $component 1
392
+ Add-TextToCMLog $LogFile " Connecting to site: $ ( $SiteCode ) " $component 1
380
393
Set-Location " $ ( $SiteCode ) :" | Out-Null
381
394
} Catch {
382
395
Add-TextToCMLog $LogFile " Could not set location to site: $ ( $SiteCode ) ." $component 3
@@ -396,10 +409,8 @@ If ((Get-CMSite).Version -lt $cmSiteVersion){
396
409
Write-Warning " $ ( $ModuleName ) requires configuration manager cmdlets $ ( $cmSiteVersion.ToString ()) or greater."
397
410
}
398
411
399
- Invoke-SyncCheck
400
-
401
412
# Try to initiate an update sync.
402
- Try
413
+ Try
403
414
{
404
415
Sync-CMSoftwareUpdate - FullSync:$FullSync
405
416
If ($FullSync ){
@@ -411,12 +422,12 @@ Try
411
422
If ($Wait ){
412
423
Start-Sleep - Seconds 30
413
424
Add-TextToCMLog $LogFile " Initiating a sync check." $component 1
414
- Invoke-SyncCheck - SyncLeadTime 0
425
+ Invoke-SyncCheck - SyncLeadTime 0
415
426
}
416
427
}
417
428
Catch [System.Exception ]
418
429
{
419
- Add-TextToCMLog $LogFile " Failed to initiate an update sync.)" $component 3
430
+ Add-TextToCMLog $LogFile " Failed to initiate an update sync.)" $component 3
420
431
Add-TextToCMLog $LogFile " Error: $ ( $_.Exception.Message ) " $component 3
421
432
Add-TextToCMLog $LogFile " $ ( $_.InvocationInfo.PositionMessage ) " $component 3
422
433
}
0 commit comments