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

标签 powershell powershell-ise

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

$Host.UI.RawUI.WindowTitle = "My Awesome New Window Title"

但我想知道如何访问在读取主机请求时弹出的窗口标题,例如:
$strP4Pass = Read-Host "Please enter Perforce Password" -assecurestring

它弹出 Windows PowerShell ISE - Input作为标题 - 是的,我知道我有我的 Please enter Perforce Password在窗口内提示 - 但我真的很想能够自定义标题 - 有什么想法吗?

最佳答案

您可以使用 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)

这将生成一个与您使用 -confirm 或 -whatif 获得的类似 UI,但您可以指定所需的响应。这适用于任何 PowerShell 主机、ISE 或 PowerShell.exe。

关于powershell - 如何在 PowerShell ISE 中更改 Read-Host 提示的 WindowTitle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5905081/

相关文章:

windows - Active Directory 中是否存在任何主键(或)唯一键?

PowerShell 将历史记录作为跨 session 的完整对象进行跟踪

powershell - 如何让 Powershell ISE 支持颜色和非 ASCII 字符?

powershell - PowerShell 2 CTP3 ISE 的自定义读取主机对话框

powershell - 调用制表符补全/Intellisense 时 PowerShell 中出现 StackOverflowException

powershell - 调用命令未按预期工作

powershell - 如何使用PowerShell 2.0远程安装(卸载)应用程序?

windows - 如何在 Windows 上录制我的 Cypress 测试?

windows - Windows高对比度主题中的Powershell ISE编辑器

security - 使用PowerShell V4通过gmail发送邮件