gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:08:29 26 4
gpt4 key购买 nike

我知道如何使用类似的东西更改主 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com