The other day I wondered how to get the equivalent of this WSUS synchronization summary and its details.
More precisely I wanted to get the summary of what you see in the mmc snap-in under the synchronizations node:
and the details that you get when you right-click a synchronization and hit ‘Synchronization report’ but I got instead the following message telling me that the report viewer wasn’t installed
After a few minutes, I found the following MSDN page about Reporting Newly Synchronized Updates
I first looked at the GetUpdates method that has many ways to call it.
The msdn article proposes to use the 2nd one where you specify all the 5 arguments:
- Microsoft.UpdateServices.Administration.ApprovedStates approvedStates,
- datetime fromArrivalDate,
- datetime toArrivalDate,
- Microsoft.UpdateServices.Administration.UpdateCategoryCollection updateCategories,
- Microsoft.UpdateServices.Administration.UpdateClassificationCollection updateClassifications
where both the updatecategories and updateclassifications are set to $null
I gave it a try but I couldn’t get reliable results 😦 even when the two collections (UpdateCategoryCollection and UpdateClassificationCollection) were properly defined and not set to null.
Forget that method, it’s too unpredictable.
I switched to the 3rd method where you just use a single updateScope object as argument instead of the above 5 arguments and finally got the expected reliability 😀
# Get the last sync info (start and end times) $lastSync = (Get-WsusServer).GetSubscription().GetLastSynchronizationInfo() # Create an updatescope object $UpdateScope = New-Object -TypeName Microsoft.UpdateServices.Administration.UpdateScope # Set the start time $UpdateScope.FromArrivalDate = $lastSync.StartTime # Set the end time $UpdateScope.ToArrivalDate = $lastSync.EndTime # Invoke the getupdates method using the update scope object $SyncUpdates = (Get-WsusServer).GetUpdates($UpdateScope)
Now to get the summary, I just do
$SyncUpdates | Group-Object -Property publicationstate -NoElement
To view the details of what was synchronized I do:
$SyncUpdates | Out-GridView # or $SyncUpdates | Select Title,SecurityBulletins,UpdateClassificationTitle,PublicationState | Sort PublicationState | Format-Table -AutoSize
Easy-peasy and as always PowerShell rocks 😎