- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- Thomas Lee
- 212字
- 2021-07-02 18:15:55
How to do it...
In this recipe you manage WSUS updates:
- Open a PowerShell session, and view the overall status of all Windows updates on WSUS1:
$WSUSServer = Get-WsusServer $WSUSServer.GetStatus()
- View the computer targets:
$WSUSServer.GetComputerTargets()
- View the installed updates on DC1 using Get-Hotfix and Get-SilWindowsUpdate:
Get-HotFix -ComputerName DC1 $CimSession = New-CimSession -ComputerName DC1 Get-SilWindowsUpdate -CimSession $CimSession $CimSession | Remove-CimSession
- Search the WSUS server for updates with titles containing Windows Server 2016 that are classified as security updates, newest to oldest, and store them in a variable. Examine the variable using Get-Member, reviewing the properties and methods of the Microsoft.UpdateServices.Internal.BaseApi.Update object:
$SecurityUpdates = $WSUSServer.SearchUpdates( `
"Windows Server 2016") | Where-Object -Property UpdateClassificationTitle `
-eq 'Security Updates' | Sort-Object -Property CreationDate -Descending $SecurityUpdates | Get-Member
- View the matching updates:
$SecurityUpdates |
Select-Object -Property CreationDate, Title
- Select one of the updates to approve based on the KB article ID:
$SelectedUpdate = $SecurityUpdates |
Where-Object -Property KnowledgebaseArticles -eq 4019472
- Define the computer target group where you will approve this update:
$DCTargetGroup = $WSUSServer.GetComputerTargetGroups() | Where-Object -Property Name -eq 'Domain Controllers'
- Approve the update for installation in the target group:
$SelectedUpdate.Approve('Install',$DCTargetGroup)
- Select one of the updates to decline based on the KB article ID:
$DeclinedUpdate = $SecurityUpdates |
Where-Object -Property KnowledgebaseArticles -eq 4020821
- Decline the update:
$DeclinedUpdate.Decline($DCTargetGroup)