Write-Information
コマンドの情報ストリーム データWindows PowerShell処理方法を指定します。
構文
Write-Information
[-MessageData] <Object>
[[-Tags] <String[]>]
[<CommonParameters>]
説明
コマンドレットはWrite-Information
、コマンドの情報ストリーム データWindows PowerShell処理方法を指定します。
Windows PowerShell 5.0 では、スクリプトとその呼び出し元 (またはホスティング環境) の間で構造化データを送信するために使用できる、新しい構造化情報ストリーム (Windows PowerShell ストリームの番号 6) が導入されています。
Write-Information
では、ストリームに情報メッセージを追加し、コマンドの情報ストリーム データWindows PowerShell処理方法を指定できます。 情報ストリームは、、ジョブ、スケジュールされたジョブ、ワークフローでも機能 PowerShell.Streams
します。
注意
情報ストリームは、メッセージの先頭に "[Stream Name]:" という標準規則に従っていません。 これは簡潔さと視覚的な清潔さを目的としていました。
ユーザー設定変数の値は $InformationPreference
、指定したメッセージ Write-Information
がスクリプトの操作で予想されるポイントに表示されるかどうかを決定します。
この変数の既定値は SilentlyContinue
既定では であるため、情報メッセージは表示されません。
の $InformationPreference
値を変更しない場合は、共通パラメーターをコマンドに追加 InformationAction
することで、その値をオーバーライドできます。
詳細については、「 about_Preference_Variables と about_CommonParameters」を参照してください。
注意
Windows PowerShell 5.0 以降では、 Write-Host
を使用Write-Information
Write-Host
して情報ストリームに出力を出力できます。
これにより、下位互換性を維持しながら、 を使用してWrite-Host
書き込まれたデータをキャプチャまたは抑制できます。
詳細については、「Write-Host」を参照してください。
Write-Information
は、サポートされているワークフロー アクティビティでもあります。
例
例 1: Get- 結果の情報を書き込む
Get-WindowsFeature -Name p*; Write-Information -MessageData "Got your features!" -InformationAction Continue
Display Name Name Install State
------------ ---- -------------
[ ] Print and Document Services Print-Services Available
[ ] Print Server Print-Server Available
[ ] Distributed Scan Server Print-Scan-Server Available
[ ] Internet Printing Print-Internet Available
[ ] LPD Service Print-LPD-Service Available
[ ] Peer Name Resolution Protocol PNRP Available
[X] Windows PowerShell PowerShellRoot Installed
[X] Windows PowerShell 5.0 PowerShell Installed
[ ] Windows PowerShell 2.0 Engine PowerShell-V2 Removed
[X] Windows PowerShell ISE PowerShell-ISE Installed
Got your features!
この例では、コマンドを実行 Get-WindowsFeature
して 、'p' で始まる Name 値を持つすべての機能を検索した後に、情報メッセージ "Got your features!" を表示します。
$InformationPreference
変数は引き続き既定の に設定されているため、 SilentlyContinue
パラメーターをInformationAction
追加して値を$InformationPreference
オーバーライドし、メッセージを表示します。
値は InformationAction
Continue です。つまり、メッセージが表示されますが、まだ完了していない場合はスクリプトまたはコマンドが続行されます。
例 2: 情報を書き込んでタグ付けする
Get-WindowsFeature -Name p*; Write-Information -MessageData "To filter your results for PowerShell, pipe your results to the Where-Object cmdlet." -Tags "Instructions" -InformationAction Continue
Display Name Name Install State
------------ ---- -------------
[ ] Print and Document Services Print-Services Available
[ ] Print Server Print-Server Available
[ ] Distributed Scan Server Print-Scan-Server Available
[ ] Internet Printing Print-Internet Available
[ ] LPD Service Print-LPD-Service Available
[ ] Peer Name Resolution Protocol PNRP Available
[X] Windows PowerShell PowerShellRoot Installed
[X] Windows PowerShell 5.0 PowerShell Installed
[ ] Windows PowerShell 2.0 Engine PowerShell-V2 Removed
[X] Windows PowerShell ISE PowerShell-ISE Installed
To filter your results for PowerShell, pipe your results to the Where-Object cmdlet.
この例では、 を使用 Write-Information
して、現在のコマンドの実行が完了した後に別のコマンドを実行する必要があることをユーザーに通知します。
この例では、情報メッセージにタグ Instructions を追加します。
このコマンドを実行した後、情報ストリームで Instructions というタグが付いたメッセージを検索すると、ここで指定したメッセージが結果の中に含まれます。
例 3: ファイルに情報を書き込む
function Test-Info
{
Get-Process P*
Write-Information "Here you go"
}
Test-Info 6> Info.txt
この例では、コード 6> を使用して、関数内の情報ストリームを Info.txt ファイルにリダイレクトします。 Info.txt ファイルを開くと、"ここでは移動します" というテキストが表示されます。
パラメーター
-MessageData
スクリプトまたはコマンドを実行するときにユーザーに表示する情報メッセージを指定します。 最適な結果を得るには、情報メッセージを引用符で囲みます。 例として、"テスト完了" があります。
Type: | Object |
Aliases: | Msg |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Tags
を使用して情報ストリームに追加したメッセージの並べ替えとフィルター処理に使用できる単純な文字列を指定します Write-Information
。
このパラメーターは、 の Tags パラメーターと同様に New-ModuleManifest
機能します。
Type: | String[] |
Position: | 1 |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
入力
None
Write-Information
はパイプ入力を受け入れません。