2017-06-23 37 views
1

我有一個我爲報告製作的powershell腳本。我在顯示安裝/不適用百分比更新時遇到問題。使用Powershell獲取已安裝/不適用的WSUS百分比

所以這裏是我創建的腳本的開始。

[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; 

正如您所看到的,這部分將顯示報表的表格。最後一個是InstalledOrNotAppableablePercentage。這是我有麻煩顯示的部分。我不知道這是否是正確的變量名稱,或者我錯過了什麼?

+0

運行'$ wsus.GetSummariesPerComputerTarget($ updatescope,$ computerscope)| Get-Member -Force'可以查看輸出對象的所有成員(屬性和方法)。 – mklement0

回答

1

有一個在對象中沒有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}}

0

我認爲,這是正確的計算:

(($_.NotApplicableCount + $_.InstalledCount)/($_.NotApplicableCount + $_.InstalledCount + $_.NotInstalledCount+ $_.FailedCount + $_.UnknownCount))*100