marabunta
Goto Top

Powershell Hashtable to Übersichtliche Darstellung

Ich frage Remote diverse Rechner ab und speichere das Ergebnis aller Rechner in $LoggedOn, die Variable liefert allerdings jeder Rechner für sich und ich bündle das in $Computers
1
2
3
4
5
6
Etwas Pseudocode
$Computers=Invoke-Command -ComputerName $Computerliste {
#Blabla
$LoggedOn=@{"Computername" = "$Computer"; "Username" = "$Username"; "Status"="$Status"}  
}
$Computers


Liefert das Ergebnis:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Name                           Value
----                           -----                                                                                                                       
Computername                   Computer1
Username                       user1
Status                         Aktiv
Computername                   Computer3
Username                       user2
Status                         Aktiv
Computername                   Computer4
Username
Status
Computername                   Computer2
Username                       user3
Status                         Aktiv

Wüsste jemand wie ich das Übersichtlich darstelle und vor allem nach Computernamen sortieren kann?
Ideal wäre sowas:
Computer1: User1 - Aktiv
Computer2: User3 - Aktiv
Computer3: User2 - Aktiv
Computer4: -

Es wird manuell ausgeführt und soll einfach schnell zeigen welcher Rechner gerade frei ist.

Content-ID: 322588

Url: https://administrator.de/forum/powershell-hashtable-to-uebersichtliche-darstellung-322588.html

Ausgedruckt am: 14.04.2025 um 12:04 Uhr

colinardo
Lösung colinardo 01.12.2016 aktualisiert um 11:47:39 Uhr
Goto Top
Hi,
mach aus der Hashtable ein Powershell-Object:

Ab PS3.0 die optimierte kurze Variante
1
[pscustomobject] @{"Computername" = $Computer; "Username" = $Username; "Status"=$Status
Mit PS2.0 Kompatibilität:
1
New-Object PSObject -Property @{"Computername" = $Computer; "Username" = $Username; "Status"=$Status
Hat zusätzlich den Vorteil das du den Inhalt bei Bedarf gleich an Export-CSV pipen kannst.

Grüße Uwe
Marabunta
Marabunta 01.12.2016 um 11:52:36 Uhr
Goto Top
Perfekt. Mit der Zeile ist es dann auch gut zu lesen
1
$Computers |select Computername, Username, Status | Sort-Object Computername |Format-Table -AutoSize