Level 1
0 / 100 XP

Command Syntax Part 2

How do you tell which Parameters are optional and which arguments are required?

To answer that question we need PowerShell’s Help system

Type help get-service -showwindow

Scroll down to the Syntax section and what I have done is I’ve copied the Syntax section into

my scripting Pane. So you can use show window and I’ll view the syntax from the scripting

pane.

Now watch this I’m going to type get-service, notice that this cmdlet runs without adding

any parameters.

Now check this out type get-eventlog press return, notice what it says:

So, the question is why did get-service run when get-eventlog required a value for the -logname parameter?

1 The answer is in the syntax of the help files for get-service and get-eventlog

Lets checkout get-service first. Let’s start with parameter set #2 and set #3

Optional [Parameter Argument] Notice that all the parameters and the arguments are

surrounded by square brackets.

This means that adding the parameters are optional and not needed. So,

2 Get-service will run without adding any parameters.

Now let’s take a look at the syntax for get-eventlog

If you want to follow along type help get-eventlog -showwindow

Again I’ve copied the syntax for get-eventlog to my scripting pane

Let’s go through the syntax, notice that almost every parameter and every argument are

surrounded by square brackets, that means that they are all optional or not needed.

Notice -logname is surrounded by square brackets but the argument is not.

Required Argument

That means, because there are square brackets around the parameter -logname, the name

logname is optional but the argument <string> is required.

That is why when you ran get-eventlog without any parameters, PowerShell asks for a

value for -logname

Now go back to get-eventlog, logname:

type Application and press retu…