我有一个powershell脚本正在为报告。我在显示安装/不适用百分比时遇到麻烦。
所以这是我创建的脚本的开始。
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration");
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("WSUSSRV",$False);
##Get updates summary per computer##
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope;
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope;
$wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) |
Format-Table @{L='ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}},
@{L='NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}},DownloadedCount,NotInstalledCount,InstalledCount,FailedCount,InstalledOrNotApplicablePercentage;
我遇到的部分是最后一个语句。
Format-Table @{L='ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}},
@{L='NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}},DownloadedCount,NotInstalledCount,InstalledCount,FailedCount,InstalledOrNotApplicablePercentage;
您可以看到,此部分将显示报告的表。最后一个是 installedornotapplicablepercentage 。这是我在展示中遇到的部分。我不知道这是正确的变量名称还是我缺少某些内容?
对象中没有InstalledOrNotApplicablePercentage
属性,但是您可以通过添加计算它的计算列来计算出来,例如:
Format-Table @{L='ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}},
@{L='NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}},DownloadedCount,NotInstalledCount,InstalledCount,FailedCount,@{L= "InstalledOrNotApplicablePercentage";e={(($_.NotApplicableCount + $_.InstalledCount) / ($_.NotApplicableCount + $_.InstalledCount + $_.NotInstalledCount+$_.FailedCount))*100}}
我认为,这是正确的计算:
(($_.NotApplicableCount + $_.InstalledCount) / ($_.NotApplicableCount + $_.InstalledCount + $_.NotInstalledCount+ $_.FailedCount + $_.UnknownCount))*100