0

是否可以将文本的颜色存储在变量中?我试过这个但它不起作用:

$format1 = "-ForegroundColor White"
$format2 = "-BackgroundColor Black"

Write-Host "Example" $format1 $format2

它返回:

"Example -ForegroundColor White -BackgroundColor Black" #(not colored)
4

1 回答 1

0

以下是您如何完成您想要实现的目标。

$format1 = @{
    ForegroundColor="White"
    BackgroundColor="Black"
}

Write-Host "Example" @format1

调用此方法Splatting,基本上是您如何使用hashtable.

于 2021-04-23T20:54:32.520 回答