我有一个字典和一个foreach输出那个字典,都在ps1文件中,我用.\MyScript.ps1
$tokenColors = @{
"None" = "White";
"Comment" = "Black";
"Keyword" = "Black";
"Command" = "DarkCyan";
"Parameter" = "Black";
"Operator" = "Gray";
"String" = "Gray";
"Number" = "Gray";
"Type" = "DarkGreen";
"Variable" = "DarkGreen";
"Member" = "DarkGreen";
}
foreach ($token in $tokenColors.Keys) {
Write-Host "${token}: $($tokenColors[$token])"
Set-PSReadlineOption -TokenKind $token -ForegroundColor $($tokenColors[$token]) -BackgroundColor DarkGray
}
这不会输出任何文字。为什么? (直接在终端中粘贴代码会产生预期的结果,但是从脚本中却没有)
PS dev:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.122
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.122
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS dev:\> (Get-WmiObject win32_operatingsystem).version
10.0.10586