Ausgaben 101¶
Gezieltes Ausgeben der Tabellen
Get-Service | Select-Object -first 5 | Format-Table
Get-Service | Select-Object -first 5 | Format-Table *
Get-Service | Select-Object -first 5 | Format-Table -property Name, CanStop
Get-Service | Select-Object * | Out-GridView
Standardausgabe gemäß DotNetTypes.Format.ps1xml (eigentlich also Dot.NET Formate!)
Get-ViewDefinition System.Diagnostics.Process # Viewdefinition Get-Process ab Zeile 431
Get-Process | Format-Table –view priority
Ausgaben einschränken
Get-Process | Format-Table -Property id,processname,workingset
als auch
Get-Process | Select-Object id, processname, workingset | Format-Table
Seitenweise Ausgabe
Get-Service | Out-Host -Paging
das alte more.exe ginge natürlich auch (aber hier asynchrone Abarbeitung - Nerv!)
Get-ChildItem c:\ -Recurse | more
Ausgabe-Cmdlets Konsole:
Write-Host,
Write-Warning und
Write-Error
Mit Write-Host manuelle Konfiguration der Ausgaben möglich
Write-Host "Hallo Joe" -foregroundcolor red -backgroundcolor white
Diverse Ausgaben:
1$a = "Joe Brandes"
2$b = "info@pcsystembetreuer.de"
3$c = Get-Date
4# und wieder: in Zeichenketten (doppelte) sind Variablen nutzbar; ansonsten immer +
5$a + " ist erreichbar unter " + $b + ". Diese Information hat den Stand: " + $c + "."
6# oder
7"$a ist erreichbar unter $b. Diese Information hat den Stand: $c."
Neu: mit Platzhaltern und Formatbezeichnern: Ausgabeoperator –f
Beispiele: (s.a. Tabelle ab S. 164ff. Schwichtenberg (PS 4.0) bzw. Tabelle S. 182 ff. (PS 5.0))
"{0} ist erreichbar unter {1}. Diese Information hat den Stand: {2:D}." -f $a, $b, $c
Weitere Beispiele:
Get-Process | ForEach-Object { "{0,-40} | {1}" -f $_.Name, ($_.ws/1MB)}
Get-Process | ForEach-Object { "{0,-40} | {1:n}" -f $_.Name, ($_.ws/1MB)}
Get-Process | ForEach-Object { "{0,-40} | {1:0.000}" -f $_.Name, ($_.ws/1MB)}