Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Param(
[string]$WsusServer = ([system.net.dns]::GetHostByName('localhost')).hostname,
[bool]$UseSSL = $False,
[int]$PortNumber = 80
)
$script:CurrentErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
#Connect to the WSUS 3.0 interface.
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
"Connecting to $WsusServer on port $PortNumber "
$WsusServerAdminProxy = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WsusServer,$UseSSL,$PortNumber);
If($? -eq $False)
{ Write-Warning "Something went wrong connecting to the WSUS interface on $WsusServer server: $($Error[0].Exception.Message)"
$ErrorActionPreference = $script:CurrentErrorActionPreference
Return
}
# Get All Updates not declined
"Getting All Updates that have not been declined "
$AllUpdates = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined}
"There are $($AllUpdates.Count) that are not declined "
#Delcine Itanium Updates
$ItaniumUpdates = $AllUpdates | ?{$_.Title -match 'ia64|itanium'}
If($ItaniumUpdates)
{
"Found $($ItaniumUpdates.Count) Itanium Updates that will be declined"
$ItaniumUpdates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Itanium Updates found that needed declining. "}
#Delcine Windows 2000 Updates
$W2kUpdates = $AllUpdates | ?{$_.ProductTitles -match 'Windows 2000'}
If($W2kUpdates)
{
"Found $($W2kUpdates.Count) Windows 2000 Updates that will be declined"
$W2kUpdates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Windows 2000 Updates found that needed declining. "}
#Delcine Windows XP Updates
$XPUpdates = $AllUpdates | ?{$_.ProductTitles -match 'Windows XP'}
If($XPUpdates)
{
"Found $($XPUpdates.Count) Windows XP Updates that will be declined"
$XPUpdates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Windows XP Updates found that needed declining. "}
#Delcine Windows Server 2003 Updates
$2K3Updates = $AllUpdates | ?{$_.ProductTitles -match 'Windows Server 2003'}
If($2K3Updates)
{
"Found $($2K3Updates.Count) Windows Server 2003 Updates that will be declined"
$2K3Updates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Windows Server 2003 Updates found that needed declining. "}
#Delcine Language Pack Updates
$2K3Updates = $AllUpdates | ?{$_.Title -match 'Language Pack|Language Interface Pack|Language Features'}
If($2K3Updates)
{
"Found $($2K3Updates.Count) Language Pack Updates that will be declined"
$2K3Updates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Windows Language Pack Updates found that needed declining. "}
#Delcine Vista Only Updates
$VistaUpdates = $AllUpdates | ?{$_.ProductTitles -eq 'Windows Vista' -and $_.ProductTitles.count -eq 1}
If($VistaUpdates)
{
"Found $($VistaUpdates.Count) Windows Vista Updates that will be declined"
$VistaUpdates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Windows Vista Updates found that needed declining. "}
#Delcine Win10 x86 Updates
$Win10x86Updates = $AllUpdates | ?{$_.ProductTitles -eq 'Windows 10' -and $_.Title -match 'for x86'}
If($Win10x86Updates)
{
"Found $($Win10x86Updates.Count) Win10 x86 Updates that will be declined"
$Win10x86Updates | %{
Write-Progress -Activity "Declining Updates" -Status "Declining $($_.KnowledgebaseArticles) - $($_.Title)"
$_.Decline()
}
}Else
{"No Win10 x86 Updates found that needed declining. "}
$ErrorActionPreference = $script:CurrentErrorActionPreference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.