是否可以将文本的颜色存储在变量中?我试过这个但它不起作用:
$format1 = "-ForegroundColor White"
$format2 = "-BackgroundColor Black"
Write-Host "Example" $format1 $format2
它返回:
"Example -ForegroundColor White -BackgroundColor Black" #(not colored)
是否可以将文本的颜色存储在变量中?我试过这个但它不起作用:
$format1 = "-ForegroundColor White"
$format2 = "-BackgroundColor Black"
Write-Host "Example" $format1 $format2
它返回:
"Example -ForegroundColor White -BackgroundColor Black" #(not colored)
以下是您如何完成您想要实现的目标。
$format1 = @{
ForegroundColor="White"
BackgroundColor="Black"
}
Write-Host "Example" @format1
调用此方法Splatting
,基本上是您如何使用hashtable
.