我正在编写 Powershell 脚本来管理 WSUS。一个脚本可以创建、读取和更新自动批准规则。但它不能删除规则。
WSUS 允许管理员制定具有重复名称的规则。如果存在多个具有相同名称的规则,则脚本需要先删除重复项,然后再继续。我找不到这样做的方法。
我从 Microsoft 的 WSUS 类库文档中提取了大量信息 (https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms744624(v=vs.85))
我的脚本需要将自动更新批准规则设置为正确的设置。
$myServer = Get-WsusServer
$rule = $myServer.GetInstallApprovalRules() | Where-Object {$_.Name -eq 'WSUS Automation Rule'} #This returns data type Microsoft.UpdatesServices.Internal.BaseApi.AutomaticUpdateApprovalRule
#********************************* Need code here****************
if ($rule.count -gt 1){
#If there is more than one rule named 'WSUS Automation Rule', delete the duplicates.
}
#********************************* Need code here****************
if ($rule = $null){
#If there is no rule with that name, make one.
$rule = $myServer.CreateInstallApprovalRule('WSUS Automation Rule')
}
#Snipped code. Create a list of update classifications in $classifications.
#Snipped code. Create a list of update categories in $categories.
$rule.setSetUpdateClassifications($classifications)
$rule.setCategories($categories)
$rule.save()
$rule.apply()