
Write-Hostを使用すると、コンソールにメッセージを表示できます。
構文
Write-Host [[-Object] <オブジェクト>] [-NoNewline] [-Separator <オブジェクト>] [-ForegroundColor <コンソールカラー>] [-BackgroundColor <コンソールカラー>]
文字列を表示
PS C:\work> Write-Host "Hello PowerShell" Hello PowerShell
-NoNewline
NoNewlineパラメータを使うと、改行が後ろに入りません。PS C:\work> Write-Host "焼肉" -NoNewline ; Write-Host "定食" 焼肉定食
-Separator
Separatorパラメータを使うと、配列を指定したセパレータで区切って表示できます。PS C:\work> Write-Host (1,2,3,4,5) -Separator "==" 1==2==3==4==5 PS C:\work> Write-Host ("a","b","c","d","e") -Separator "; " a; b; c; d; e
テキストの色と背景色を変更する
ForegroundColorパラメータとBackgroundColorパラメータを使うことによって、文字の色と背景色を変更することが出来ます。PS C:\work> Write-Host "Hello PowerShell" -foregroundcolor red -backgroundcolor yellow Hello PowerShell実行するとこんな感じになります。

この機能を使ってこんなことをしてみました。

なんかいろいろ遊べそうです。
スポンサーリンク