Skip to content

Instantly share code, notes, and snippets.

@AdilHindistan
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdilHindistan/9877358 to your computer and use it in GitHub Desktop.
Save AdilHindistan/9877358 to your computer and use it in GitHub Desktop.
#AH - AdilHindistan - 2014-02-04
## Enumerate UpdateRelationship values and their meaning with this code:
[System.Enum]::GetValues([Microsoft.UpdateServices.Administration.UpdateRelationship]) | ForEach-Object -Process {
'{0} -> {1}' -f ([Microsoft.UpdateServices.Administration.UpdateRelationship]::$_.Value__),$_
}
# View superseded updates that were previously approved
(Get-WsusServer).SearchUpdates("2010") | Where {
($_.IsSuperseded) -and
($_.isApproved)
} | ForEach-Object -Process {
$_ | Add-Member -MemberType ScriptProperty -Name UpdatesThatSupersedeThisUpdate -Value {
($this.GetRelatedUpdates(5)).Title
} -Force -PassThru
} | ? UpdatesThatSupersedeThisUpdate -notmatch "Service\sPack\s2" |
fl Title,SecurityBulletins,IsApproved,UpdatesThatSupersedeThisUpdate
## Using PoshWsus module
$SomeKBArticles | % { Get-PoshWSUSUpdate -Update $_ | add-member -membertype ScriptProperty -Name SupersededBy -value {($this.GetRelatedUpdates(5)).Title} -force -PassThru }
# Check the date of the last sync (it's configured to sync manually)
(Get-WsusServer).GetSubscription().GetLastSynchronizationInfo()
# Initiate a sync
(Get-WsusServer).GetSubscription().StartSynchronization()
# View its progress
(Get-WsusServer).GetSubscription().GetSynchronizationStatus()
# Check that the last sync date is today and a success
(Get-WsusServer).GetSubscription().GetLastSynchronizationInfo()
# Find any update that has 'Windows 7' string mentioned
$allW7updates = (Get-WsusServer).SearchUpdates("Windows 7")
# Select my target group of computers
$targetgroup = (Get-WsusServer).GetComputerTargetGroups() |
Where Name -eq "Windows 7 x64"
# View all the x64 updates for Windows 7
$allW7updates | Where { (-not($_.IsSuperseded)) -and
($_.Title -match "x64") -and
($_.UpdateClassificationTitle -eq "Security Updates") -and
(-not($_.isApproved)) -and
(-not($_.isDeclined))
} |
ft Title,State,KnowledgebaseArticles,SecurityBulletins -AutoSize
# Mark these required updates as 'to be installed' by client computers
$allW7updates | Where { (-not($_.IsSuperseded)) -and
($_.Title -match "x64") -and
($_.UpdateClassificationTitle -eq "Security Updates") -and
(-not($_.isApproved)) -and
(-not($_.isDeclined))} |
Where {
$_.Title -notmatch ".NET Framework 4"
} | ForEach-Object -Process {
$_.Approve(
[Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install,
$targetgroup
)
}
# View superseded updates that were previously approved
$allW7updates | Where {
($_.IsSuperseded) -and
($_.isApproved)
} | ft Title,SecurityBulletins
# Remove them by flagging them as 'not approved'
$allW7updates |
Where { ($_.IsSuperseded) -and ($_.isApproved) } |
ForEach-Object -Process {
$_.Approve(
[Microsoft.UpdateServices.Administration.UpdateApprovalAction]::NotApproved,
$targetgroup
)
}
### OFFICE
# View all Office 2010 (32bit) updates
(Get-WsusServer).SearchUpdates("2010") | Where {
(-not($_.IsSuperseded)) -and
($_.Title -match "32-bit") -and
($_.UpdateClassificationTitle -eq "Security Updates") -and
(-not($_.isApproved)) -and
(-not($_.isDeclined))
} | ft Title,SecurityBulletins,IsApproved,IsSuperseded -AutoSize
# Mark these required updates as 'to be installed' by client computers
(Get-WsusServer).SearchUpdates("2010") | Where {
(-not($_.IsSuperseded)) -and
($_.Title -match "32-bit") -and
($_.UpdateClassificationTitle -eq "Security Updates") -and
(-not($_.isApproved)) -and
(-not($_.isDeclined))
} | ForEach-Object -Process {
$_.Approve(
[Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install,
$targetgroup
)
}
# View superseded updates that were previously approved
(Get-WsusServer).SearchUpdates("2010") | Where {
($_.IsSuperseded) -and
($_.isApproved)
} |
ft Title,SecurityBulletins,IsApproved,IsSuperseded -AutoSize
# Remove them by flagging them as 'not approved'
(Get-WsusServer).SearchUpdates("2010") | Where {
($_.IsSuperseded) -and
($_.isApproved) } |
ForEach-Object -Process {
$_.Approve(
[Microsoft.UpdateServices.Administration.UpdateApprovalAction]::NotApproved,
$targetgroup
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment