繁体   English   中英

Powershell 错误:使用“2”参数调用“批准”的异常:值不能是 null

[英]Powershell Error: Exception Calling “Approve” with “2” argument(s): Value cannot be null

我正在编写一个 powershell 脚本来自动化 WSUS。 其中一项功能批准对沙盒测试计算机组的非替代更新,以便在控制台上下载/安装它们。 但是,它找到的所有更新都会返回相同的错误。 这是我的定义和批准 function 的代码:


[String]$updateServer1 = hostname
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 8530
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$useSecureConnection,$portNumber)
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$u = $updateServer.GetUpdates($updatescope)
$install = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install
$group = $updateServer.GetComputerTargetGroups | where-object {$_.Name -eq "Update Testing"}

function Approve-Nonsuperseded {
    Write-host "Creating new Computer Group to approve updates for installation..." -foregroundcolor green
    try {
        $updateserver.CreateComputerTargetGroup("Update Testing") 
        }
    catch {
        Write-host "Update Group already exists. Moving on..." -ForegroundColor Green
        }
    $count = 0
    Write-host "Approving new updates for installation..." -foregroundcolor green
    foreach ($u2 in $u )
        {
        if ($u2.IsDeclined -ne 'True' -and $u2.IsSuperseded -ne 'True' -and $u2.CreationDate -ge $PatchDay)
            {
                write-host Approving Update : $u2.Title
                $u2.Approve($install,$group)
                $count = $count + 1
            }
        }
    write-host Total Approved Updates: $count
}

它返回所有要被批准的正确更新,但总是在 $u2.Approve($install,$group) 行上给我同样的错误。 我会很感激任何见解。 谢谢!

$u2应该是一个字符串而不是一个变量。 尝试使用$u2.Approve("Install",$group)

[Microsoft.UpdateServices.Administration.UpdateApprovalAction] 命名空间仅提供选项;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM