Search code examples
powershellparam

powershell and switch parameter type


I can't get this working and from documentation and examples on the web i cannot work out why.

My code is simple, its just a script to which i want to pass a parameter, not every time. so i've laid the param section as thus

param(
[Parameter(Mandatory=$true)]
[string]$startOfName,

[ValidateRange(0,6)]
[int]$numberOfServers = 1,

[switch]$consecutiveNumbers

)

and im calling the scipt as follows.

.\Get-NextServerName.ps1 -startOfName servername -numberOfServers 5 -consecutiveNumbers

which gives me the lovely error message:

Get-NextServerName.ps1 : A parameter cannot be found that matches parameter name 'consecutiveNumbers'.

Can anyone see anything that I'm doing wrong?


Solution

  • This looks like being a bug in Powergui.Tried it from a command prompt and it worked first time. still won't work in Powergui. Think it might be related to the way it passes command line arguments from the shell pane to the script. Probably going to open a call to discuss, unless I find out im on a way old version.