Command Syntax Part 3
Full-Access Members Only
Sorry, this lesson is only available to Server Academy Full-Access members. Become a Full-Access member now and get instant access to this and many more premium courses. Click the button below and get instant access now.
Instructions
Q&A (0)
Notes (0)
Resources (0)
Saving Progress...
Resources
There are no resources for this lesson.
Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.
{ } Curly braces. In some of the commands you’ll see curly braces. I’ll show you what I mean.
Back to the parameter set 1. Checkout the parameter -Entrytype.
Notice that it is surrounded by square brackets that start at -EntryType and end at warning} ]. That shows that the parameter is optional.
But notice the curly braces surrounding {Error and ending at warning}
Also notice the vertical lines between information | FailureAudit | SuccessAudit and Warning.
What this means is, that if you want to use the parameter -Entrytype you have these choices.
Let’s try this
Type Get-EventLog application -EntryType warning, error -Newest 20.
As you can see this command ran correctly.
This command displays any warnings and errors coming from our applications that we are currently running.
Required Parameters
There’s One thing that I need to show you.
Let go back to the syntax for get-service. Take a look at the first parameter set, notice that the parameter -displayname doesn’t have the square brackets around it.
This means that if you want to use the first parameter set, you would be required to use the parameter -DisplayName.
That’s how you know what is required and what is optional.
Type get-service -displayname and pick an application press return, and as you can see that did command run. This command displays the service that is associated with the application.
So, in most instances this rule would hold true.
If there are no square brackets around the parameter and the argument, the parameter and the argument are required.
If there are square brackets around the parameter and the argument the parameter is optional and not required.
Let’s go back to the get-evenlog syntax and review:
Get in the habit of analyzing the syntax of a cmdlet
- – indicates a parameter
- < > angle brackets indicate an argument
- [ ] If there are two square brackets inside two angle brackets this means that the parameter can take multiple arguments, separated by a comma. In this case it would be two numbers.
- [Param Arg] Square brackets around the parameter and the argument.
Means the parameter is optional .
[Param] Square brackets around the parameter
Because -logname is surrounded by square brackets and the argument <string> is not, that makes -logname optional and the argument required.
- Positional Because -logname is surrounded by square brackets
and it’s position is 0, this makes this parameter positional.
So, PowerShell expects -logname and it’s value type to be first in the order of cmdlets.
- Named
- { } Curly braces - a parameter followed by several choices separated by vertical lines and surrounded by curly braces.
Using this parameter, you can choose various items to expand the functionality of the cmdlet.
So, with what you have learned in the last two lectures you should be able to figure out command syntax. You’re on your way to understanding a lot more about PowerShell.
Server Academy Members Only
Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.