Author Posts

April 18, 2018 at 12:39 am

Hi everyone,

I tried posting this over at Stack Overflow but didn't get a great answer. Apparently this community is better for PowerShell though so I hope someone can help :).

Is there a way to have PowerShell display the options possible for a parameter? I have the following Parameter which requires one of the resource groups in Azure to be selected.

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true, HelpMessage = "Enter the name of the resource group you would like to use.")]
    [ValidateScript( {$_ -in (Get-AzureRMResourceGroup | Select-Object -ExpandProperty ResourceGroupName)})]
    [String]$ResourceGroup
)

ValidateScript will check to see if it is one of the Resource groups in Azure, but my question is how can I display a list of the resource groups so that the person running the script knows what possible options they can input for the parameter? Can I use Write-Host or something within the Param block?

If possible I don't want to maintain the options manually so if it could check the resource groups in Azure and then provide a list for the script runner to choose from that would be great.

thanks

April 18, 2018 at 12:42 am

ValidateScript is an odd puppy in terms of tab completion. Using a normal parameter, no, PowerShell can't auto-complete. What you're after is a Dynamic Parameter, I suspect, which let you run code in different places to accomplish that. Dig into https://foxdeploy.com/2017/01/13/adding-tab-completion-to-your-powershell-functions/ for some examples.

That said, tab completion is what PowerShell offers – there's no pop-up menus, or on-screen lists, or anything else. So if you want something more than tab completion of available values, you're entirely on your own.

April 18, 2018 at 12:43 am

Hi everyone,

I recently asked this question over at Stack Overflow but didn't get a great answer, I hope someone here can help.

Is there a way to have PowerShell display the options possible for a parameter? I have the following Parameter which requires one of the resource groups in Azure to be selected.

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true, HelpMessage = "Enter the name of the resource group you would like to use.")]
    [ValidateScript( {$_ -in (Get-AzureRMResourceGroup | Select-Object -ExpandProperty ResourceGroupName)})]
    [String]$ResourceGroup
)

ValidateScript will check to see if it is one of the Resource groups in Azure, but my question is how can I display a list of the resource groups so that the person running the script knows what possible options they can input for the parameter? Can I use Write-Host or something within the Param block?

I would prefer it was a dynamic list as each person that runs the script may have different resource group options to choose.

thanks