2008wsus创建和管理计算机组,一次为一个计算机组批准WSUS更新

这是我最终使用的代码。它有效,但我不禁感觉有更好的方法。

.Synopsis

Approve WSUS updates for installation.

.DESCRIPTION

This script takes the name of a WSUS approval group, and approves updates based on their age.

.NOTES

Author: Mike Hashemi

V1 date: 24 Feb 2014

.LINK

.PARAMETER PrimaryWSUSServer

Default value: server.domain.local. This parameter specifies the DNS name of the primary WSUS server.

.PARAMETER PatchingGroup

Manadatory parameter. Valid values are 'Alpha','Beta','Production','Excluded','Workstations','COC-OMI-WORKSTATIONS'. The value of this parameter determines what patching groups will have updates approved for installation. Multiple groups can be entered at once, unless one of the is Alpha

.EXAMPLE

.\manageWSUSUpdates-Parameterized.ps1 -PatchingGroup Alpha

In this example, the script will approve all updates with an approval status not equal to 'IsDeclined', for installation to servers in the Alpha group.

.EXAMPLE

.\manageWSUSUpdates-Parameterized.ps1 -PatchingGroup Beta

In this example, the script will get the list of updates approved for the Alpha group, in the last three months (from the date the script is run), and will approve them for installation to servers in the Beta group.

#>

[CmdletBinding()]

param(

[string]$PrimaryWSUSServer = “server.domain.local”,

[Parameter(Mandatory=$True)]

[ValidateSet('Alpha','Beta','Production','Excluded','Workstations','COC-OMI-WORKSTATIONS')]

[string[]]$PatchingGroup

)

#Initialize variables

$BeginScriptTime = Get-Date

# Load the Required .NET assembly

[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($PrimaryWSUSServer,$False)

Function Approve-AlphaPatches {

#Get the list of all updates that are not declined.

$unapprovedUpdates = $wsus.getupdates() | where {$_.isdeclined -ne $true}

#If an update has a license agreement, accept it

$license = $unapprovedUpdates | where {$_.RequiresLicenseAgreementAcceptance}

$license | ForEach {$_.AcceptLicenseAgreement()}

#Get members of Alpha patching group.

$installGroup = $wsus.GetComputerTargetGroups() | where {$_.Name -eq $PatchingGroup}

#Approve updates for the Beta group.

Foreach ($update in $unapprovedUpdates) {

$update.Approve(“Install”,$installGroup)

}

}

Function Approve-NonAlphaPatches {

Foreach ($group in $PatchingGroup) {

#Get the updates that have arrived in the last three months.

$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope

$updateScope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved

$updateScope.FromArrivalDAte = (Get-Date).AddMonths(-3)

#Get the updates approved for the Alpha group.

$alphaGroup = $wsus.GetComputerTargetGroups() | Where {$_.Name -eq 'Alpha'}

$updateScope.ApprovedComputerTargetGroups.add($alphaGroup)

$Updates = $wsus.GetUpdates($updateScope)

#Get members of Alpha patching group.

$installGroup = $wsus.GetComputerTargetGroups() | where {$_.Name -eq $group}

#Approve updates for the user-specified patching group.

Foreach ($update in $updates) {

$update.Approve(“Install”,$installGroup)

}

}

}

#Begin Script

If (($PatchingGroup.Count -gt 1) -and ($PatchingGroup -ccontains 'Alpha')) {

Write-Error ("This script cannot approve Alpha patches with other patching groups. If you want to approve more groups at the same time, please approve the rest in a second execution of the script.")

Return

}

Else {

If ($PatchingGroup -eq 'Alpha') {

Approve-AlphaPatches

}

Else {

Approve-NonAlphaPatches

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值