こんにちは、今日は指定オブジェクトをパイプラインの次のコマンドに送信するコマンドレットWrite-Outputの使い方についてまとめていきます。
このコマンドがパイプラインの最後のコマンドである場合は、オブジェクトがコンソールに出力されます。
確認環境
PSVersion 5.1.18362.1110
Write-Outputの使い方
文字列を渡し、その後にパイプをつなげない場合はそのままその文字列がコンソールに出力されます。
1 | Write-Output "test" |
以下のようにGet-Memberコマンドレットにパイプラインで出力を渡すと、文字列オブジェクトSystem.Stringのメンバー情報が出力されます。
1 2 3 4 5 6 7 8 9 10 11 | PS C:\Users\santerabyte> Write-Output "test" | Get-Member TypeName: System.String Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone(), System.Object ICloneable.Clone() CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(System.Object obj), int IComparable [string] .CompareTo(string other) Contains Method bool Contains(string value) ... |
リンク
Write-Output (Microsoft.PowerShell.Utility) – PowerShell | Microsoft Docs
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-output?view=powershell-7.1