Skip to content

Instantly share code, notes, and snippets.

@klishb
Created April 19, 2017 14:47
Show Gist options
  • Save klishb/33370b1d1f7854f1bea724644b589fcf to your computer and use it in GitHub Desktop.
Save klishb/33370b1d1f7854f1bea724644b589fcf to your computer and use it in GitHub Desktop.
Approves WSUS updates for servers
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
Position=0)]
[string]$WsusServer = "myserver",
[int]$Port = "8530",
[Parameter(Mandatory=$true)]
[int]$DaysOld = "0",
[Parameter(Mandatory=$true)]
[string]$WSUSGroup = "Servers"
)
#Requires -Modules @{ModuleName="PoshWSUS";ModuleVersion="2.3.1.2"}
Connect-PSWSUSServer -WsusServer $WsusServer -port $Port
$Categories = Get-PSWSUSCategory | Where {
($_.title -eq 'Microsoft SQL Server 2012') -or
($_.title -eq 'Microsoft SQL Server 2014') -or
($_.title -eq 'Microsoft SQL Server 2016') -or
($_.title -eq 'SQL Server 2008 R2') -or
($_.title -eq 'SQL Server 2008') -or
($_.title -eq 'SQL Server 2012 Product Updates for Setup') -or
($_.title -eq 'SQL Server 2014-2016 Product Updates for Setup') -or
($_.title -eq 'Windows Server 2003, Datacenter Edition') -or
($_.title -eq 'Windows Server 2003') -or
($_.title -eq 'Windows Server 2008 R2') -or
($_.title -eq 'Windows Server 2012 R2')
}
$Classifications = Get-PSWSUSClassification | Where {
($_.Title -eq “Updates”) -or
($_.Title -eq “Security Updates”) -or
($_.Title -eq “Critical Updates”)
}
$TargetGroup = Get-PSWSUSGroup -Name $WSUSGroup
$UpdatesRecentlyReleased = Get-PSWSUSUpdate -ToCreationDate ((get-date).AddDays(-$DaysOld)) -Category $Categories -Classification $Classifications -ComputerTargetGroups $WSUSGroup -ApprovedState NotApproved
$UpdatesRecentlyReleased | where {
($_.title -notlike "*security only*") -and
($_.title -notlike "*preview*") -and
($_.title -notlike "*Itanium-based*")
} | Approve-PSWSUSUpdate -Action Install -Group $TargetGroup -passthru -WhatIf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment