Here is a revised script (still draft) that uses a function to get the job done. In this example, I call the function three times to produce a waterfall effect of approvals with a 14 day lag. I place my low-impact workstations in the
Workstations - Update 1st group, and place my high-impact workstation in the
Workstations - Update 4th group. I have a rule to auto-approve new updates to the Workstations - Update 1st group as they arrive to the WSUS server.
Function ApprovalsWaterfall($predecessorName, $successorName, [int]$maturityInterval) {
#Define the start of time
$genesis = Get-Date "1/1/2000 12:00 AM"
#Figure out the cutoff date
$maturityDate = Get-Date
$maturityDate = $maturityDate.adddays(-$maturityInterval)
write-host "Approving updates for" $successorName "that have been approved for" $predecessorName "for at least" $maturityInterval "days..." -ForegroundColor Cyan
write-host
#Establish Predecessor and Successor Groups
$predecessor = $wsus.GetComputerTargetGroups() | Where-Object {$_.Name -eq $predecessorName}
$successor = $wsus.GetComputerTargetGroups() | Where-Object {$_.Name -eq $successorName}
#Discover approved updates that have matured in predecessor group and approve for sucessor group if not already
$install = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.UpdateApprovalActions = [Microsoft.UpdateServices.Administration.UpdateApprovalActions]::Install
$wsus.GetUpdates($updateScope) | foreach {
if ($_.GetUpdateApprovals($predecessor, $install, $genesis, $maturityDate).Count -ne 0 -and $_.GetUpdateApprovals($successor)[0].Action -eq $null) {
write-host $_.Title -ForegroundColor Green
write-host "Released Date:"$_.CreationDate
write-host "Arrival Date:"$_.ArrivalDate
write-host "ApprovalDate:"$_.GetUpdateApprovals($predecessor)[0].CreationDate
write-host
$_.Approve($install,$successor)
}
}
}
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
ApprovalsWaterfall "Workstations - Update 1st" "Workstations - Update 2nd" 14
ApprovalsWaterfall "Workstations - Update 2nd" "Workstations - Update 3rd" 14
ApprovalsWaterfall "Workstations - Update 3rd" "Workstations - Update 4th" 14