我正在为我拥有的脚本制作一个菜单系统,我可以通过使用菜单或将它们作为参数传递给脚本来更改我需要的值。我目前的烦恼之一是在菜单刷新时输入新值后,菜单文本中的变量不会更新为新值。
$global:drive="C:"
$title = "Setup
"
$message = "The default variables are:
VARIABLES TO CHANGE
1. The Drive Location: $global:drive <<<--- This is the variable that does not update after I change it when I run the script.
"
$one = New-Object System.Management.Automation.Host.ChoiceDescription "&1 Drive", "The Drive Location:"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($one)
:OuterLoop do
{
for ($i = 1; )
{
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result)
{
0 {$global:drive = Read-Host "Drive is $global:drive .Set the Drive Location";
"The Drive is now: $global:drive";
break;}
}
}
}
while ($y -ne 100)
最初我没有将变量设置为全局,但在此处阅读可能会有所帮助。它没有,但也没有伤害。我也尝试将其设置为脚本。变量确实发生了变化,所以这比任何东西都更美观。
谢谢