marabunta
Goto Top

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:

[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 

Content-Key: 428502

Url: https://administrator.de/contentid/428502

Printed on: April 25, 2024 at 08:04 o'clock

Mitglied: 138810
138810 Mar 14, 2019 at 11:13:02 (UTC)
Goto Top
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
Member: Marabunta
Marabunta Mar 14, 2019 at 11:31:43 (UTC)
Goto Top
Das hilft zwar, aber die Erfassung der WSUS Updates mit den Ids und Status für die Untergruppen ist bereits Problematisch.
Wenn ich die zu fassen kriege, ist das bauen des Objekts wahrscheinlich relativ leicht.
Mitglied: 138810
138810 Mar 14, 2019 updated at 12:01:41 (UTC)
Goto Top
Wenn ich die zu fassen kriege
Ein zwei Kaffee und ab die Post face-wink.
Mitglied: 77559
77559 Mar 14, 2019 at 17:28:37 (UTC)
Goto Top
Zitat von @Marabunta:
$Updates | ForEach-Object {
$update = $_
ForEach-Object ist langsamer als ein foreach, wenn du sowieso das aktuelle Object kopierst kannst du besser so coden:

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