Press "Enter" to skip to content

Interlinked Parameters In Powershell

Rob Sewell shows how to make one parameter’s valid set of values depend upon a previous parameter’s selected value:

But what Sander wanted was to validate the value of the second parameter depending on the value of the first one. So lets say we wanted

  • If word is sun, number must be 1 or 2
  • If word is moon, number must be 3 or 4
  • If word is earth, number must be 5 or 6

We can use the ValidateScriptAttribute  to do this. This requires a script block which returns True or False. You can access the current parameter with $_ so we can use a script block like this

Any Powershell post with a link to June Blender is automatically 5% better in my book.