How can I change the WindowTitle at the Read-Host prompt in PowerShell ISE?

I know how to change the title of the main ISE window using something like

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

but I'm wondering how to access the window name that appears on the Read-Host request, for example:

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

It appears with Windows PowerShell ISE - Input as a title - and yes, I know that I have a Please enter Perforce Password prompt in the window - but I really want to be able to customize the title - any ideas?

+4
source share
2 answers

You can create a custom invitation with several options using 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 create a similar user interface that you get with -confirm or -whatif, but you can specify the answers you want. This will work in any PowerShell Host, ISE or PowerShell.exe.

+7
source

This is a personal answer, but for me, ISE is a WorkFrame for editing and debugging your scripts. I prefer PowerGUI for this.

This is NOT the last PowerShell interpreter to execute your scripts. Therefore, if you want to add a user interface to your code, you can take a look at how to integrate Windows Forms or WPF into your scripts. There are also some modules that will help you with this.

Here is the Microsoft series about WPF

WPF and PowerShell - Part 1 (Hello World and Welcome to the Week of WPF)

WPF and PowerShell - Part 2 (Learning WPF (and the rest of .NET) with scripts)

WPF and PowerShell - Part 3 (Event Handling)

Take a look at WPK ( WPF PowerShell Toolkit )

+2
source

All Articles