如何在PowerShell ISE中更改Read-Host提示符的WindowTitle?

ran*_*0m1 4 powershell powershell-ise

我知道如何使用类似的方式更改主ISE窗口的标题

$Host.UI.RawUI.WindowTitle = "My Awesome New Window Title"
Run Code Online (Sandbox Code Playgroud)

但我想知道如何访问弹出读取主机请求的窗口标题,如:

$strP4Pass = Read-Host "Please enter Perforce Password" -assecurestring
Run Code Online (Sandbox Code Playgroud)

它以Windows PowerShell ISE - Input标题的形式出现 - 是的,我知道我窗口中有Please enter Perforce Password提示- 但我真的希望能够自定义标题 - 任何想法?

And*_*der 7

您可以使用System.Management.Automation.Host.ChoiceDescription创建具有多个选项的自定义提示

$Yes = New-Object System.Management.Automation.Host.ChoiceDescription "Yes Please"
$No = New-Object System.Management.Automation.Host.ChoiceDescription "No, Thank you"
$YesNoChoices = [System.Management.Automation.Host.ChoiceDescription[]]($No,$Yes)
$Answer = $Host.UI.PromptForChoice("Caption goes here", "Message Goes here", $YesNoChoices, 1)
Run Code Online (Sandbox Code Playgroud)

这将生成与-confirm或-whatif相似的UI,但您可以指定所需的响应.这适用于任何PowerShell主机,ISE或PowerShell.exe.