You can use PowerShell for WSUS management. This example works on a Windows Server with Powershell 5.1 and the Powershell WSUS module installed from Server Manager. You can start the synchronization and approve the updates with the example below:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wsus = Get-WSUSserver | |
$Subscription = $wsus.GetSubscription() | |
# Start de WSUS Synchronization. | |
$Subscription.StartSynchronization() | |
# Wait Until the the Synchronizations is finished. | |
Start-Sleep -Seconds 5 | |
While($Subscription.GetSynchronizationProgress().Phase -ne "NotProcessing"){ | |
Write-Host "Synchronization is busy: $($Subscription.GetSynchronizationProgress())" | |
Start-Sleep -Seconds 5 | |
} | |
Get-WSUSUpdate -Approval AnyExceptDeclined | Approve-WSUSUpdate -Action Install -TargetGroupName "All Computers" |
You can use this example if you like to deny older updates:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all updates older then 4 months: | |
$Updates = Get-WSUSUpdates -Approval AnyExceptDeclined | Where-Object{!($_.update.creationdate -ge (Get-Date).Addmonths(-4))} | |
# Deny the updates: | |
$Updates | Deny-WSUSupdate |
Sometimes it is necessary to accept a license agreement for an update. You can use this code to accept all license agreements:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wsus = Get-WSUSServer | |
# Get a list of updates with a License Agreement. | |
$AcceptLicenses = $wsus.GetUpdates() | Where-Object {$_.HasLicenseAgreement -eq "True"} | |
# Accept the License Agreement for the updates. | |
ForEach($Item in $AcceptLicenses){ | |
$item.AcceptLicenseAgreement() | |
} |
No comments:
Post a Comment