Error executing script in powershell WSUS GetUpdate()

I executed a Powershell script, but I got an error

Script

[datetime]$dataIni = "2017/01/01" 
[datetime]$dataFim = "2017/01/20"

$serverWsus = "server1"

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

Write-Progress -Activity 'Getting updates...' -PercentComplete 0

$updatesneeded = $wsus.GetUpdate() | ? {($_.CreationDate -gt 
[datetime]$dateFirst -and 
$_.CreationDate -lt [datetime]$dateLast) -and 
($_.Title -notmatch "Itanium" -and 
$_.Title -match "Windows Server 2008 x64" -and  
$_.UpdateClassificationTitle -eq "Security Updates")} 

$i = 0
$total = $updatesneeded.Count
foreach ($update in $updatesneeded) 
{ 
 Write-Progress -Activity 'Approving updates...' -Status "%Complete" -
 PercentComplete (($i/$total) * 100)
 Approve-WsusUpdate -Update $update -Action Install -TargetGroupName 'enviroment'
 $i++
 }
 Write-Host "Updates approved: $total" -ForegroundColor Yellow

Error

Cannot find an overload for "GetUpdate" and the argument count: "0".

At line:11 char:1 + $updatesneeded = $wsus.GetUpdate() | ? {($_.CreationDate -gt [datetime]$dateFirs ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Approve-WsusUpdate : Cannot bind parameter 'Update'. Cannot convert the "Microsoft.UpdateServices.Internal.BaseApi.Update" value of type "Microsoft.UpdateServices.Internal.BaseApi.Update" to type "Microsoft.UpdateServices.Commands.WsusUpdate". At line:22 char:32 + Approve-WsusUpdate -Update $update -Action Install -TargetGroupName 'enviroment' + ~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Approve-WsusUpdate], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.UpdateServices.Commands.ApproveWsusUpdateCommand

链接地址: http://www.djcxy.com/p/29092.html

上一篇: 设置Windows PowerShell路径变量

下一篇: 在powershell中执行脚本时出错WSUS GetUpdate()