2011-05-05 36 views
4

我知道如何用什麼來改變主ISE窗口的標題像如何在PowerShell ISE中更改Read-Host提示的WindowTitle?

$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提示窗口 - 但我真的希望能夠自定義標題 - 任何想法?

回答

7

您可以創建多個自定義提示微軟使用System.Management.Automation.Host.ChoiceDescripti進行選擇on

$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中使用。

+0

謝謝!正是我在找什麼! – rand0m1 2011-05-07 00:02:06

+0

爲了使這更容易,我創建了一個PowerShell模塊[get-MultipleChoiceQuestionAnswered](https://github.com/ChrisMagnuson/get-MultipleChoiceQuestionAnswered),以便我可以編寫諸如'$ Priority = get-MultipleChoiceQuestionAnswered -Question'什麼優先級這個請求應該有這個級別嗎?「 - 選擇1,2,3,4' – 2015-05-18 13:58:06

2

這是一個個人答案,但對我來說,ISE是一個WorkFrame來編輯和調試你的腳本。我更喜歡PowerGUI

它不是執行您的scipts的最終PowerShell解釋器。所以,如果你想爲你的代碼添加UI,你可以看看如何在你的腳本中集成Windows Forms或WPF。它也存在一些模塊來幫助你。

這裏是一個系列有關WPF

WPF & PowerShell – Part 1 (Hello World & Welcome to the Week of WPF)

WPF & PowerShell – Part 2 (Exploring WPF (and the rest of .NET) with Scripts)

WPF & PowerShell -- Part 3 (Handling Events)

,看一下朝鮮勞動黨(WPF PowerShell Toolkit

+0

你說得很好 - 我不希望我的最終用戶使用ISE - 但是對於我自己的測試,我使用KeePass來自動化大量的重複性手動輸入,這會爲我的奇蹟自己的易用性。我會檢查這些資源,感謝指導! – rand0m1 2011-05-07 00:03:47

相關問題