简体   繁体   English

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

[英]How can I change the WindowTitle of the Read-Host prompt in the PowerShell ISE?

I know how to change the title of the main ISE window using something like 我知道如何使用类似的方式更改主ISE窗口的标题

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

but I'm wondering how to get access to the title of the window that pops upon a Read-Host request like: 但我想知道如何访问弹出读取主机请求的窗口标题,如:

$strP4Pass = Read-Host "Please enter Perforce Password" -assecurestring

It pops with Windows PowerShell ISE - Input as the title - and yes, I know I have my Please enter Perforce Password prompt within the window - but I'd really like to be able to customize the title - any ideas? 它弹出Windows PowerShell ISE - Input作为标题 - 是的,我知道我有我的Please enter Perforce Password 窗口 Please enter Perforce Password提示 - 但我真的希望能够自定义标题 - 任何想法?

You can create a custom prompt with multiple choices using System.Management.Automation.Host.ChoiceDescription 您可以使用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)

This will produce a similar UI that you get with -confirm or -whatif, but you can specify the responses you want. 这将生成与-confirm或-whatif相似的UI,但您可以指定所需的响应。 This will work in any PowerShell Host, ISE or PowerShell.exe. 这适用于任何PowerShell主机,ISE或PowerShell.exe。

This is a personal answer, but for me ISE is a WorkFrame to edit, and debug your scripts. 这是个人答案,但对我来说ISE是一个用于编辑和调试脚本的WorkFrame。 I prefer PowerGUI for that. 我更喜欢PowerGUI

It's NOT the final PowerShell interpreter to execute your scipts. 它不是执行你的scipts的最终PowerShell解释器。 So if you want to add UI to you code you can Have a look on how to integrate Windows Forms or WPF in you scripts. 因此,如果要为代码添加UI,可以查看如何在脚本中集成Windows窗体或WPF。 It also exists some modules to help you that way. 它还有一些模块可以帮助你。

Here is a Microsoft serie about WPF 这是一个关于WPF的微软系列

WPF & PowerShell – Part 1 ( Hello World & Welcome to the Week of WPF ) WPF和PowerShell - 第1部分(Hello World和欢迎来到WPF周)

WPF & PowerShell – Part 2 (Exploring WPF (and the rest of .NET) with Scripts) WPF和PowerShell - 第2部分(使用脚本探索WPF(以及.NET的其余部分))

WPF & PowerShell -- Part 3 (Handling Events) WPF和PowerShell - 第3部分(处理事件)

Have a look to WPK ( WPF PowerShell Toolkit ) 看看WPK( WPF PowerShell Toolkit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM