Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How it works...

In this recipe, you see how to configure WSUS updating.

In step 1, you use Get-WsusProduct to perform searches for products supported by Windows Update by title:

In step 2, you store a list of the chosen product titles in a variable:

In step 3, you use Get-WsusProduct to retrieve the WsusProduct objects with titles that match your list and pipe these to Set-WsusProduct to enable the synchronization of updates for these products in WSUS:

In step 4, you use Get-WsusClassification to review which classifications of updates are available from Windows Update:

In step 5, you store the list of desired update classifications in a variable and view it:

In step 6, you use Get-WsusClassification to retrieve the WsusClassification objects with titles that match your list and pipe these to Set-WsusClassification to enable the synchronization of these categories of updates in WSUS:

In step 7, you use Get-WsusServer to create a $WSUSServer object. Use the GetSubscription method on that object to create a Subscription object:

In step 8, you use the StartSynchronization method on the UpdateServer object to begin synchronization, and use a do-while loop to wait for the synchronization process to start by waiting until the result of the GetSynchronizationProgress method changes from NotProcessing. The $IntervalSeconds variable determines the time between checks. You can increase this value to 60 to check every minute. Once started, you use a do-until loop to watch the value of the same method as it returns the progressive stages of the synchronization, and wait for the process to complete and return NotProcessing once more:

In step 9, you use the GetLastSynchronizationInfo method on the Subscription object to review the results of the synchronization:

In step 10, if you want your WSUS server to download updates from Microsoft automatically, you use the Subscription object to configure automatic synchronization once daily and save the configuration: