デバッグ出力の文字色指定とISE [PowerShell]
PowerShellのコンソールに Write-Debug と Write-Verbose で出力される文字列の色は初期状態ではどちらも黄色になっています。違う色にしたほうが見分けやすいと思いスクリプト内で
ところがこれを ISE の中で実行すると次のようなエラーになってしまいます。
$Host.PrivateData.VerboseForegroundColor = 'DarkGreen' $Host.PrivateData.VerboseBackgroundColor = 'Black'のように指定して詳細出力はダークグリーンに変更していました。
ところがこれを ISE の中で実行すると次のようなエラーになってしまいます。
Property 'VerboseForegroundColor' cannot be found on this object; make sure it exists and is settable.ISE内では$host が標準のコンソールとは違うものになっていて PrivateData プロパティが存在しません。
#### ISE内の $host ####ということでWindows PowerShell ISE Host での色指定の方法がわからないので、とりあえずその場合には指定をしないという安易な回避策をとっています。
Name : Windows PowerShell ISE Host
Version : 2.0
InstanceId : f80a1692-70bd-498d-96c5-1ba368660197
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : ja-JP
CurrentUICulture : ja-JP
PrivateData :
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
#### 標準コンソールの $host ####
Name : ConsoleHost
Version : 2.0
InstanceId : ca20e341-fa77-4860-9499-bb51a84fae11
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : ja-JP
CurrentUICulture : ja-JP
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
if ($Host.Name -eq 'ConsoleHost') { $Host.PrivateData.VerboseForegroundColor = 'DarkGreen' $Host.PrivateData.VerboseBackgroundColor = 'Black' }どうすれば指定できるのだろう。
タグ:powershell
コメント 0