One annoying error I have just stumbled over. When using the Parameter keyword don’t put a space after it. If you do this
[Parameter (Position=0,HelpMessage="The length of password. Default is random between 8 and 12")]
you will get this error
Cannot find type for custom attribute ‘Parameter ‘. Please make sure the assembly containing this type is loaded.
At C:Scriptswippassword.ps1:29 char:20
+ [Parameter <<<< (Position=0,HelpMessage="The length of password. Default is random between 8 and 12")]
+ CategoryInfo : InvalidOperation: (Parameter :Token) [], RuntimeException
+ FullyQualifiedErrorId : CustomAttributeTypeNotFound
for it to run correctly you need to use
[Parameter(Position=0,HelpMessage="The length of password. Default is random between 8 and 12")]
notice that the opening ( comes immediately after the word Parameter
One to watch
Good to know. Here strings suffer a similar fate.$x = @""@spaces after the quote on the first line cause an error.
Here strings should have nothing after the opening quote but a line feed\carriage returnBeware copying here strings from blog posts etc you can often introduce a space after the opening quote which can be difficult to track down
Pingback: Microsoft – Powershell – Parameters (Command Line) | Daniel Adeniji's – Learning in the Open
Thanks. Save me a big headache. Now I can go without the Aspirin.