this is hashtable in my powershell script (data extracted using Get-PSReadlineOption):
$theme = @{}
$theme["CommentForegroundColor"] = "DarkGreen"
$theme["CommentBackgroundColor"] = "Black"
$theme["KeywordForegroundColor"] = "Green"
$theme["KeywordBackgroundColor"] = "Black"
I am trying to set powershell theme colors using Set-PSReadlineOption command:
foreach ($colorTokenKey in $theme.keys) {
$c=$theme[$colorTokenKey]
echo "$colorTokenKey will be set to $c"
$colorTokenArgs = $colorTokenKey.Replace("ForegroundColor"," -ForegroundColor")
$colorTokenArgs = $colorTokenArgs.Replace("BackgroundColor"," -BackgroundColor")
$colorTokenArgs = $colorTokenArgs.Split(" ")
$tokenKind = $colorTokenArgs[0]
$tokenForegroundOrBackground = $colorTokenArgs[1]
$params = "-TokenKind $tokenKind $tokenForegroundOrBackground $c"
echo $params
& Set-PSReadlineOption $params
}
But when I run this, I get
CommandBackgroundColor will be set to White -TokenKind Command -BackgroundColor White Set-PSReadlineOption : Cannot bind parameter 'TokenKind'. Cannot convert value "-Tok enKind Command -BackgroundColor White" to type "Microsoft.PowerShell.TokenClassifica tion". Error: "Unable to match the identifier name -TokenKind Command -BackgroundCol or White to a valid enumerator name. Specify one of the following enumerator names a nd try again: None, Comment, Keyword, String, Operator, Variable, Command, Parameter, Type, Number , Member" At C:\Users\...\PowerShellColors.ps1:88 char:28 + & Set-PSReadlineOption $params
What I am doing wrong?