Hallo Forum,
Ich versuche per Powershell die Anzahl der zur Verfügung stehenden Updates zu bestimmen.
hier ein Snipped:
function getImportantWindowsUpdates ([int] $installupdates = 0) {
$UpdateSession = New-Object -Com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$updatecount = 0
$updateobject = @{
unknown = 0
low = 0
moderate = 0
important = 0
critical =0
}
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
For ($X = 0; $X -lt $SearchResult.Updates.Count; $X++){
$Update = $SearchResult.Updates.Item($X)
switch ($Update.MsrcSeverity) {
{ "unknown" } { $updateobject.unknown++; continue }
{ "low" } { $updateobject.low++ ; continue }
{ "moderate" } { $updateobject.moderate++ ; continue }
{ "important" } { $updateobject.important++ ; continue }
{ "critical" } { $updateobject.critical++ ; continue }
Default { $updateobject.unknown++; continue }
}
}
return $updateobject
}
$osupdates = getImportantWindowsUpdates
Write-Output ("Updates.. optional: " + $osupdates.unknown + " low: " + $osupdates.low + " moderate: " + $osupdates.moderate + " important: " + $osupdates.important + " critical: " + $osupdates.critical)Auf einem testserver erhalte ich lediglich die Ausgabe 5 unknown/optional.. in der Windows GUI sehe ich aber 5 optional und 1 important update.
Es sind sicher auch nur 5 Objekte in
$UpdateSearcher
enthalten.
Was mache ich falsch?
Danke und Gruss,
Andreas








