Hi
About the brackets surrounding a parameter name, or rather, when they DON’T surround a parameter name.
In the MVA Powershell 3,0 Jump Start course Jason Helmick covered this but not in a way that resulted in me understanding it.
Consider the second parameter set for Get-Service:
Get-Service [-ComputerName <String>] [-DependentServices] [-Exclude <String>] [-Include <String>] [-RequiredServices] -DisplayName <String> [<CommonParameters>]
The DisplayName parameter is NOT surrounded by (aka “binkies”, bless him). Since denotes ‘optional’, the implication is that -DisplayName is not optional…but clearly it is since I can run
Get-Service -ComputerName DC
Get-Service -ComputerName DC -name bit*
and both will produce valid output. So, I don’t have to use -DisplayName.
Does it mean that if I want to use DisplayName I have to type it? Well, no, because it’s not a positional parameter like -Name, since -Name is shown in the Help with the syntax of [[-Name] <String>], and it’s those extra around the -Name parameter itself that show it’s a positional parameter so therefore you don’t have to type it in (but just enter the argument(s)).
In the course Jason said “If you’re going to use it, you’ve got to type it in and you’ve got to give me a value.”
Well, OK, but then if I’m going to use -Name I also HAVE to give it an value. But while I don’t HAVE to type it in (because it’s a positional parameter) I do HAVE to type in any of the other parameters, with arguments if they take them, if I want to use them.
So why does “-DisplayName <String>” not have the surrounding ?