PowerShell Anzeige von WSUS-Updates nach Gruppen mit IDs
Hallo,
ich würde gerne die WSUS-Updates mit einem Skript auslesen und dabei anzeigen lassen, welche Updates für welche Gruppe (es gibt Untergruppen: Alle Clients -> W10, W7, Server...) in welchem Status (Approved...) sind .
Der Grundgedanke war, dass im Grunde die Gruppen als Spaltenbeschriftung oben stehen und darunter der UpdateName, UpdateId und Status ggf. mit Datum stehen.
Idealerweise Maschinenlesbar um per Skript weitermachen zu können. Wie z.B. Approve UpdateId 123 für Gruppe W10.
Ich denke ein PSCustomObject wäre das richtige, damit komme ich aber nicht klar und bitte um Hilfe.
Ich habe dazu bisher folgende Basis gefunden, dass zu viel und nicht ganz genau genug ist:
ich würde gerne die WSUS-Updates mit einem Skript auslesen und dabei anzeigen lassen, welche Updates für welche Gruppe (es gibt Untergruppen: Alle Clients -> W10, W7, Server...) in welchem Status (Approved...) sind .
Der Grundgedanke war, dass im Grunde die Gruppen als Spaltenbeschriftung oben stehen und darunter der UpdateName, UpdateId und Status ggf. mit Datum stehen.
Idealerweise Maschinenlesbar um per Skript weitermachen zu können. Wie z.B. Approve UpdateId 123 für Gruppe W10.
Ich denke ein PSCustomObject wäre das richtige, damit komme ich aber nicht klar und bitte um Hilfe.
Ich habe dazu bisher folgende Basis gefunden, dass zu viel und nicht ganz genau genug ist:
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
#$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::NotApproved
#$updatescope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::NotInstalled
#$updatescope.FromArrivalDate = [datetime]"12/13/2017"
$WSUSSERVER="SERVER1234"
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("$WSUSSERVER",$false,8530)
# ApprovedUpdatestoXML
# \Update Services 3.0 API Samples and Tools\ApprovedUpdatesToXML
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.ApprovedStates = (
([Microsoft.UpdateServices.Administration.ApprovedStates]::HasStaleUpdateApprovals.value__+
[Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved.value__)
)
# get the list of updates that are approved, or have an older revision that is approved
$Updates = (Get-WsusServer).GetUpdates($updateScope)
# calling IUpdate.GetUpdateApprovals once for each update can be expensive, so instead
# we use call IUpdateServer.GetUpdateApprovals() to get all approvals for all updates at once
$allUpdateApprovals = (Get-WsusServer).GetUpdateApprovals($updateScope)
# similarly, construct a table of target group
$allTargetGroups = (Get-WsusServer).GetComputerTargetGroups()
$Updates | ForEach-Object {
$update = $_
[PSCustomObject]@{
Id = $update.Id.UpdateId.ToString() ;
Title = $update.Title ;
Classification = $update.UpdateClassificationTitle ;
Approvals = $(
if ($update.IsApproved) {
# This revision (the latest revision) is approved; get the approvals and write them
$allUpdateApprovals | Where {
$_.UpdateID.UpdateID -eq $update.Id.UpdateId
} |
ForEach-Object {
$approval = $_
[PSCustomObject]@{
RevisionNumber = $update.Id.RevisionNumber ;
TargetGroup = ($allTargetGroups | Where { $_.ID -eq $approval.ComputerTargetGroupId }).Name ;
Approval = $approval.Action ;
Deadline = $(
if ($_.Deadline -lt ([datetime]::maxvalue)) {
$_.Deadline
} else {
"None"
}
) ;
ApprovalDate = $approval.CreationDate ;
}
}
} elseif ($update.HasStaleUpdateApprovals) {
# This revision has older revisions that are approved; get their approvals and write them
$update.GetRelatedUpdates(
[Microsoft.UpdateServices.Administration.UpdateRelationship]::AllRevisionsOfThisUpdate
) | Where isApproved |
ForEach-Object {
$revision = $_
$revision.GetUpdateApprovals() |
ForEach-Object {
$approval = $_
[PSCustomObject]@{
RevisionNumber = $update.Id.RevisionNumber ;
TargetGroup = ($allTargetGroups | Where { $_.ID -eq $approval.ComputerTargetGroupId }).Name ;
Approval = $approval.Action ;
Deadline = $(
if ($_.Deadline -lt ([datetime]::maxvalue)) {
$_.Deadline
} else {
"None"
}
) ;
ApprovalDate = $approval.CreationDate ;
}
}
}
} else {
}
) ;
}
} | Out-GridView
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 428502
Url: https://administrator.de/forum/powershell-anzeige-von-wsus-updates-nach-gruppen-mit-ids-428502.html
Ausgedruckt am: 02.04.2025 um 05:04 Uhr
4 Kommentare
Neuester Kommentar

Ich denke ein PSCustomObject wäre das richtige, damit komme ich aber nicht klar und bitte um Hilfe.
Powershell: Everything you wanted to know about PSCustomObject
Wenn ich die zu fassen kriege
Ein zwei Kaffee und ab die Post 
ForEach-Object ist langsamer als ein foreach, wenn du sowieso das aktuelle Object kopierst kannst du besser so coden:
Dein PSCustomObject mit Code mit PSCustomObject mit CODE ... ist reichlich unübersichtlich,
wie soll die Struktur denn letztendlich aussehen und kannst du das mit Out-GridView überhaupt sinnvoll darstellen?
Gruß
LotPings
foreach($update in $Updates){
Dein PSCustomObject mit Code mit PSCustomObject mit CODE ... ist reichlich unübersichtlich,
wie soll die Struktur denn letztendlich aussehen und kannst du das mit Out-GridView überhaupt sinnvoll darstellen?
Gruß
LotPings