Benutzer mit den meisten Antworten
Zusammenführen von Objekten,Arraylists & Zweck von Hashtables

Frage
-
Hallo zusammen
Ich habe ein Skript geschrieben, welches von einem Wsus Server Informationen über N-Server holt.
Parallel dazu werden auf jedem Server separat Informationen mittels Invoke-Command abgefragt.
Nun möchte ich diese Informationen zusammenführen.
Ich möcht hier keinen konkreten Lösungsweg, aber vielleicht wäre ein Lösungsansatz schön :)
Ausserdem seht ihr ja vielleicht gerade noch, was ich bei meinen Funktionen noch verbessern könnte (Bezüglich Objekten,Arraylists, usw.).
Machen hier vielleicht Hashtables Sinn?
Grüss Powerturtle
Wer sich die Qual antun will :)function Get-WsusClients { param ( [String[]]$Groups ) $WsusClients = @() Foreach ($Group in $Groups) { $GroupObject = $Global:WSUS.GetComputerTargetGroups() | ? {$_.Name -eq $Group} If(-not[String]::IsNullOrEmpty($GroupObject.GetChildTargetGroups())){ $ChildGroups = $GroupObject.GetChildTargetGroups() Foreach ($ChildGroup in $ChildGroups) { #Get Clients from Child Groups $WsusClients += $ChildGroup.GetComputerTargets() | % {$_.FullDomainName} } } #Get Clients from Wsus Group $WsusClients += $GroupObject.GetComputerTargets() | % {$_.FullDomainName} } return $WsusClients } function Get-WsusInformation { param ( [string[]]$Members ) $WsusClients = Foreach ($Member in $Members) { If(-Not([String]::IsNullOrEmpty($Member))) { Try{ $WSUS.GetComputerTargetByName($Member) } Catch{} } } #Updatescope definieren (Welche Updates geprüft werden sollen pro Client) $UpdateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope $UpdateScope.ExcludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::Installed, [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::NotApplicable $WsusInformationArr = New-Object system.Collections.ArrayList #Für jeden Client soll es alle Updates holen und auf die UpdateApprovalAction prüfen Foreach ($WsusClient in $WsusClients) { Try{ $WsusUpdateArr = New-Object system.Collections.ArrayList #Jedes Update von jedem Server, welches nicht den Status "Not Approved" hat, soll es weiter bearbeiten für Ausgabe $WsusClient.GetUpdateInstallationInfoPerUpdate($UpdateScope) | ? {$_.UpdateApprovalAction -ne "NotApproved"} | % { $UpdateObj = New-Object System.Object | Select-Object -Property UpdateTitle, UpdateApprovalAction, UpdateInstallationState $UpdateObj.UpdateTitle = Try{($_.GetUpdate()).Title}Catch{"No Title"} $UpdateObj.UpdateApprovalAction = $_.UpdateApprovalAction $UpdateObj.UpdateInstallationState = $_.UpdateInstallationState $WsusUpdateArr.add($UpdateObj) | Out-Null } $WsusObj = New-Object System.Object | Select-Object -Property ComputerTarget,LastReport,Updates, Group $WsusObj.ComputerTarget = $WsusClient.FullDomainName $WsusObj.LastReport = $WsusClient.LastReportedStatusTime $WsusObj.Updates = $WsusUpdateArr $WsusObj.Group = ($Global:Wsus.GetComputerTargetGroups() | ? {$_.Id -eq ($WsusClient.ComputerTargetGroupIds[1])}).Name $WsusInformationArr.add($WsusObj) | Out-Null } Catch{} } return $WsusInformationArr } function Get-Information { $result = New-Object System.Object | Select-Object -Property Computername, Domain, OS, LastBootUpTime, Services #Get-WMI for Operating System $WMIOS = Get-WmiObject -Class Win32_OperatingSystem -Property Caption,LastBootUpTime $result.OS = $WMIOS.Caption $result.LastBootUpTime = ($WMIOS.ConvertToDateTime($WMIOS.LastBootUpTime)).ToString() #Get-WMI for Computer System $WMICS = Get-WmiObject -Class Win32_ComputerSystem -Property Name,Domain $result.Computername = $WMICS.Name $result.Domain = $WMICS.Domain $result.Services = Get-Service return $result } #Auf Wsus verbinden [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null $WSUS = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(‘WsusServer.Domäne’,$False) #Alle Server von der Wsus-Gruppe holen $Servers = Get-WsusClients -Groups "Wsus-Gruppe" #Für jeden Server die Funktion Get-Information Remote ausführen und als Job laufen lassen Foreach ($Server in $Servers) { Invoke-Command -ComputerName $Server -AsJob -JobName $Server -ScriptBlock ${function:Get-Information} | Out-Null } #Auf Job-Beendigung warten Wait-Job * -Timeout 600 | Out-Null #Alle Server-Informationen in Variable füllen $ServerInformationObj = Receive-Job * -ea SilentlyContinue #Alle Wsus-Informationen in Variable füllen $WsusInformationen = Get-WsusInformation -Members $Servers
Antworten
-
Für einen klassichen Join bietet sich diese Lösung an:
http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx
Der Artikel enthält neben dem Script Join-Object auf ein erklärendes Beispiel.
Einziger Nachteil ist Performance. Ich hatte ca. 25.000 Objekte abzugleichen und mache das jetzt doch in C#.
-Raimund
- Als Antwort vorgeschlagen Alex Pitulice Donnerstag, 21. März 2013 09:01
- Als Antwort markiert Powerturtle Freitag, 22. März 2013 07:33
Alle Antworten
-
Für einen klassichen Join bietet sich diese Lösung an:
http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx
Der Artikel enthält neben dem Script Join-Object auf ein erklärendes Beispiel.
Einziger Nachteil ist Performance. Ich hatte ca. 25.000 Objekte abzugleichen und mache das jetzt doch in C#.
-Raimund
- Als Antwort vorgeschlagen Alex Pitulice Donnerstag, 21. März 2013 09:01
- Als Antwort markiert Powerturtle Freitag, 22. März 2013 07:33
-
Hallo,
wenn die Thematik abgeklärt ist, markiere bitte Raimunds Beitrag "als Antwort".
Viele Grüße,
AlexAlex Pitulice, MICROSOFT
Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip „IT-Pros helfen IT-Pros“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.