>> Hello, everyone. I'm instructor Gerri Roberts,
and this is PowerShell Scripting.
In this video, we're going to talk
about what a command is,
and how commands are structured in PowerShell.
First of all, what is a command?
Simply put, a command is just a bunch of
words or a single word that's
been put together to do
>> something such as Get- EventLog,
>> which would help you retrieve an EventLog in Windows.
In PowerShell, they are also called
cmdlets, or commandlets.
There are pre-defined cmdlets in PowerShell,
and some that you can add.
Packages of commands are often called modules.
There are modules for some things that you can add.
These could be for a program or a specific task.
For example, there are modules
specifically made for Azure,
and there are actual modules made
specifically for scripting tasks.
In PowerShell, there's usually
a structure to the command or the cmdlet.
Here we have an example of
a command that's trying to get an EventLog,
and specifically looking for the one called
Security on the computer Gerri-PC2.
At the end, we're telling it that
we want a lot of information.
Verbose means that you're going
to add a lot of extra information.
Now if we break down this command,
we can see that at the beginning,
the first item is a verb,
the second item is a noun.
Typically in PowerShell,
commands are structured with a verb, noun.
This one's a Get-EventLog,
and a lot of times you have
commands that are Get- something.
You'll also have commands that are Set-
something or Add- something a lot.
Now the difference here is
>> when you do a Get- something,
>> you're usually just pulling information.
When you're doing a Set- something,
you're usually actually setting a value
such as a username or a password for an account.
If you're doing an Add- something,
you're usually adding a new something
like a new user or a new group.
The next thing you'll notice after
our verb-noun structure is a parameter.
A parameter is an item where we can put information in.
Here, we have a parameter for logged name.
We're telling it that we're looking for
a specific log and then putting
in a parameter value so it knows which log to find.
In this case, it's Security.
Now we also have another parameter here, computer name.
Now we're telling it we're
looking for the LogName, Security,
and then we're going to look for it
on this specific computer,
and we pass the value Gerri-PC2.
Now notice here that
these parameters only have a single value.
Some parameters can have multiple values,
and those values typically are separated by
commas or quotation marks
depending on the structure
>> of that particular parameter.
>> Now at the end, you notice that you do
have a switch parameter.
Now, there are different types of parameters.
Here we see parameters that take values,
and such parameter is a parameter
that does not take your value,
but does do something.
Nouns and parameters are normally in singular form.
That just means commands and
parameters will not usually have an s at the end.
Here's an example we have Get-ADUser.
When we put that command in and
we put it in the dashes for
the parameters and we put
>> in those pieces of information,
>> we'll be able to get information
about an Active Directory user.
However, if we added an s at the end,
and we did Get-ADUsers,
we're going to get a big old nice block of
red text that's an error and it's
>> not going to be happy.
>> Make sure when you're typing it out this command,
that you look and see is this one
that has an s because those are very rare.
Sometimes those are things like
Get-process or Get-services or things like
that from the computer
where the name of the item already had
an s. Most modules
also have information on where they come from.
In the example above,
when you look at that cmdlet,
you see the AD for Active Directory.
Another thing you'll notice when
you're putting in commands,
if it's from a specific module,
you're probably going to have some sort of
information in it to tell you where it's coming from,
such as our Active Directory example.
Now spacing, case-sensitive, and other considerations.
Watch your spacing, seriously.
Improperly spaced commands just are not going to run,
you're going to get a whole lot of
red text and you're not going to be happy.
PowerShell uses these spaces to know when
to look for the next item in the list.
It will continue until it is
lost if there is not proper spacing.
What will happen is the command will run and
then if hits where it's not proper spacing,
it's going to go, oops, I don't know what that is.
Here's a bunch of errors telling
you that I don't know what that is.
Another thing with PowerShell, case-sensitive.
Some modules in PowerShell are
case-sensitive, some are not.
Quite a few of them.
If you were to write that Get-ADUser we
saw earlier all in lowercase would still work.
But the important part to remember is
things that are values like file paths,
file names, folder paths,
all that should be properly
capitalized to avoid confusion because it's
not going to find what you need or do what you need
if it doesn't know the proper value.
If you're just not sure if a module
requires proper capitalization, just do it anyways.
It's not going to hurt to do
capitalization when you don't need to necessarily.
The other thing, use proper symbols.
For example, don't accidentally put
an underscore in a command that requires a dash,
and put your slashes in the correct direction.
File paths or anything like that that requires a slash,
if the slash is in the wrong direction,
it's not going to find it,
it's not going to do it,
you're going to have a bad day.
Make sure you put your
>> slashes in the correct direction.
>> Post assessment question time.
What is a parameter called that has
no values being passed through it?
If you remember back a couple slides,
we talked about that.
Is that a zero parameter,
is that a switch parameter,
is that a blank parameter,
or a parameter null?
You can pause for a moment to figure out your answers.
Our answer here is B, a switch parameter.
A switch parameter has no value being
passed through it and will only have one effect.
For example, in our example earlier, verbose.
Verbose is put there to add
additional information about the output of the item.