【发布时间】:2017-11-29 08:43:38
【问题描述】:
我想提示以编程方式生成的列表中的选项。
背景: 我有 2 个包含不同环境的 AWS 账户。 该脚本会自动检测您所在的帐户,然后会提示您要加入的环境。
我正在尝试这个:
$envs = "
1,Dev
1,Test
1,Demo
2,Staging
2,Production
" | ConvertFrom-Csv -Delimiter "," -header "awsAccount","Environment"
$awsAccount = Determine-awsAccount
$envs = ([string]($allServers.Environment | Where-Object -property awsAccount -eq $awsAccount | Sort-Object | Get-unique)).replace(" ",",")
$title = "Deploy into which environment"
$message = "Please select which environment you want to deploy into"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($envs)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
您可以使用
$options = [System.Management.Automation.Host.ChoiceDescription[]]("yes","no")
但在我的情况下,它会弹出一个选项,其中包含我所有的环境,用逗号分隔。我希望它为每个(相关)环境弹出一个选项。
如何将环境字符串列表从 PowerShell 内部世界弹出到 PowerShell 外部世界?
【问题讨论】:
标签: arrays powershell prompt