0

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?

Something like this would be great to display on the line above where they input the value for the parametera (but not static options I want the script to query azure and display the list of resource groups the user can choose):

Please choose one of the following resource Groups: RG1 RG2 RG3 RG4

Thank you.

4
  • Hello, thanks for the advice but it isn't quite what I am looking for. I want the script to query azure and display a list of possible options. I also don't want it after they make a mistake but displayed for them to read above where they need to input the data.
    – user7995177
    Apr 17, 2018 at 4:18
  • 1
    Then implement argument completer. Apr 17, 2018 at 4:19
  • Interesting... let me Google that ;)
    – user7995177
    Apr 17, 2018 at 4:21
  • Related: stackoverflow.com/questions/26100674/… Apr 17, 2018 at 4:33

1 Answer 1

0

As PetSerAI mentioned the answer is to use tab completion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.