Easier to do it here.
This is the part that doesn't make sense to me. In section 3.5.2 it says:
What if you try to run a command and forget one of the mandatory parameters? Take a look at the help for Get-EventLog, for example, and youâ€™ll see that the -LogName parameter is mandatoryâ€”the parameter isnâ€™t enclosed in square brackets. Try running Get-EventLog without specifying a log name.
But -LogFile IS enclosed in brackets. I know further down the page it goes on explaining positional parameters but as I'm reading the book in sequence and making sure I understand every paragraph until I move onto the next one I struggled with that statement.
Does that make sense?
Great book by the way so far 😀
(So, please use the PowerShell Q&A forum – gets more attention; this forum is intended for site feedback)
All parameters take the form:
Except switch parameters, which don't have a value type of course.
is a mandatory positional parameter. That's what -LogName is on Get-EventLog. Mandatory, because the ENTIRE PARAMETER (including its value) isn't in square brackets. Positional, because the PARAMETER NAME ONLY is in square brackets.
The book is accurate. While -LogName's PARAMETER NAME is indeed in square brackets, that does not constitute the ENTIRE PARAMETER. Maybe that's the part that's confusing? A parameter is not just its name; it's also the corresponding value. Unless it's a simple switch. Just one of those things you have to get used to.
is an optional parameter. The entire thing is in [brackets].
is an optional, positional parameter. That is, you don't HAVE to specify the parameter at all. However, if you do, you can omit the parameter name provided you put the corresponding value in the correct position.
If it helps, use the full help (Help Get-EventLog -Full), since the individual parameter documentation makes the whole positional/mandatory thing much clearer.
Thanks for replying!
You are correct in the part that was confusing me. I was defining (in my mind) that a parameter was JUST the name. Not the name + the value.
You must be logged in to reply to this topic.