我需要创建脚本,该脚本将根据用户输入运行不同的代码块。
为此,我在 PS 中使用 PromptForChoice 方法。我的代码目前如下所示:
$title = 'Disk clear'
$question = 'What do you want to remove?'
$choices = '&Browser cache','&Temp folder'
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
switch ($decision)
{
0 {'You selected Browser cache'}
1 {'You selected Temp folder'}
Default {}
}
当我运行脚本时,我得到以下输出:
Disk clear
What do you want to remove?
[B] Browser cache [T] Temp folder [?] Help (default is "T"):
如果我输入 ?为了获得帮助(找出 B 和 T 的含义),我得到了:
B -
T -
我的问题是,如何编辑选项(B & T)的描述?
选择的选项实际上是类型[System.Management.Automation.Host.ChoiceDescription] https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.host.choicedescription?view=powershellsdk-7.0.0并包含一个将帮助消息指定为第二个字符串参数的选项。
$title = 'Disk clear'
$question = 'What do you want to remove?'
$Choices = @(
[System.Management.Automation.Host.ChoiceDescription]::new("&Browser Cache", "Clear the BrowserCache")
[System.Management.Automation.Host.ChoiceDescription]::new("&Temp Folder", "Clear the TempFolder")
)
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Output
Disk clear
What do you want to remove?
[T] Temp Folder [B] Browser Cache [?] Help (default is "B"): ?
T - Clear the TempFolder
B - Clear the BrowserCache
[T] Temp Folder [B] Browser Cache [?] Help (default is "B"):
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)