Domekologe icon

Decline-WSUSUpdates

Domekologe | PRO | 10/22/19 12:41:11 PM UTC | 0 ⭐ | 262 👁️ | Never ⏰ | []
PowerShell |

950 B

|

None

|

0 👍

/

0 👎

$Searchstring="Preview of Monthly"
 
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
# Retrieve only updates that have not yet been approved
$updateScope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::NotApproved
# Retrieve only updates that are installable
$updateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
$totalUpdateCount = $wsus.GetUpdateCount($updateScope)
$qualityUpdates = $wsus.GetUpdates($updateScope) | Where-Object {$_.Title -like '*$Searchstring*'} 
$qualityUpdateCount = $qualityUpdates.Length
if ($qualityUpdateCount -gt 0) {
    $wsus.GetUpdates($updateScope) | Where-Object {$_.Title -like '*$Searchstring*'}  | ForEach {
        $_.Decline()
    }
}

Comments