Moin Dani,
DESoft schrieb on 07.04.10 um 12:16:41:
Joh ... ich war auch erstaunt.
das ging mir früher schon so. Nachdem ich jahrelang irgendwelche selbstgeschriebenen Funktionen benutzt habe, irgendwann festgestellt, daß es die schon lange in der MFC gab ..
Hier jedenfalls noch die Powershell-Funktion. Die hier in einem größeren Rahmen läuft, also Servernamen ermitteln, aus den Ergebnissen einen String für Nagios basteln, etc. pp.
Der Aufruf sieht z.B. so aus:
get-UpdateInstallationStatus <WSUS-Server> <FullDomainName> <status>
bzw. um die Anzahl zu ermitteln
@(get-UpdateInstallationStatus <WSUS-Server> <FullDomainName> <status>).count
Um die Anzahl genehmigter, aber nicht installierter Updates abzufragen:
@(get-UpdateInstallationStatus <WSUS-Server> <FullDomainName> "NotInstalled" | where { ($_.IsApproved) }).count
lg
Jörg
################################################################################
# berichtet per Computer über den jeweiligen UpdateStatus
# "Downloaded", "Failed", "Installed", "InstalledPendingReboot", "NotApplicable", "NotInstalled", "Unknown", "All"
#
################################################################################
function Get-UpdateInstallationStatus {
param ([string] $UpdateServer = <servername>,[string]$ComputerName,[string]$InstallationState)
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($UpdateServer,$false)
$computerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope;
$computerScope.NameIncludes = $ComputerName
$computers = $wsus.GetComputerTargets($computerScope)
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
# check this computer
foreach ($computer in $computers) {
# get Targetgroup for this computer
$myTG = Get-ComputerTargetGroupByName $UpdateServer $computer.RequestedTargetGroupName
# get updates for this InstallationsState
$updateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]:

$InstallationState);
$updatesPerComputer = $computer.GetUpdateInstallationInfoPerUpdate($updateScope)
# $SummeUpdates = ($updatesPerComputer).Count
foreach ($update in $updatesPerComputer) {
$neededUpdate = $wsus.GetUpdate($update.UpdateId)
# info for this update
$obj = New-Object psObject
$obj | Add-Member NoteProperty Computername $computer.FullDomainName
$obj | Add-Member NoteProperty Title $neededUpdate.Title
$obj | Add-Member NoteProperty KB $neededUpdate.KnowledgebaseArticles
$obj | Add-Member NoteProperty ID $update.UpdateId
$obj | Add-Member NoteProperty InstallationState $update.UpdateInstallationState
$UpdateIsApproved = $false
$tmpTG = $myTG
if ($neededUpdate.GetUpdateApprovals($tmpTG).Count -ne 0) {
$UpdateIsApproved = $true
} else {
while ($tmpTG.Name -ne 'All Computers') {
$tmpTG = $tmpTG.GetParentTargetGroup()
if ($neededUpdate.GetUpdateApprovals($tmpTG).Count -ne 0) {
$UpdateIsApproved = $true
break
}
}
}
$obj | Add-Member NoteProperty IsApproved $UpdateIsApproved
if ($UpdateIsApproved) {
$obj | Add-Member NoteProperty ApprovalIn $tmpTG.Name
} else {
$obj | Add-Member NoteProperty ApprovalIn "not approved"
}
Write-Output $obj
}
}
}
################################################################################