PowerShell 色の付いた文字を出力する
PowerShellで色付文字を出力するには、Write-Host コマンドの
-ForegroundColor や -BackgroundColor オプションを使用します。
-ForegroundColor 文字色
-BackgroundColor 背景色
Write-Host ”こんにちわ、コルタナです” -ForegroundColor ”Green”
Write-Host ”こんにちわ、コルタナです” -BackgroundColor "Red"
-ForegroundColor と -BackgroundColor を同時に指定することもできます。
$colors = @'
White Black Gray DarkGray Blue DarkBlue Green DarkGreen Cyan DarkCyan Red DarkRed Magenta DarkMagenta Yellow DarkYellow
'@ -split "\s"
foreach ($color in $colors) {
Write-Host $color -ForegroundColor $color
Write-Host $color -BackgroundColor $color
Write-Host $color -BackgroundColor $color -ForegroundColor "DarkGray"
}
#PowerShell #コマンドレット #プログラミング #プログラミング学習 #プログラミング初心者 #Windows #ForegroundColor #BackgroundColor
この記事が気に入ったらサポートをしてみませんか?