There's nothing special about running a command in
PowerShell once you know what you want to run.
Type the command at the PowerShell prompt and press Enter.
I bet you can guess what this command's going to do based on the name.
PowerShell runs the command and displays the results.
Now in the Windows world, PowerShell commands are not case sensitive.
I'll come back to this when I get to the demo,
but I'm going to encourage you to take advantage of tab completion
and other console tricks to quickly bring up the command or
PowerShell expression that you want to run.
PowerShell does not mean a lot of typing of you're smart about how you work.
Many commands can be customized through parameters.
These help you refine your command so that it does
exactly what you need it to do.
You should read the help for a command to learn about the
different parameters and how they operate,
but it's very easy to add them to your command.
You can use tab completion.
Start typing the parameter name like ‑dri, and press Tab.
PowerShell will cycle through all parameters that begin with those letters.
Now in some commands, you can also tab complete possible parameter values.
Another option is to use keyboard shortcuts that are
part of the PSReadline module.
These commands come automatically installed in PowerShell.
You'll see these when I get to the demo.
A few quick words about PowerShell command parameters.
These too follow a convention, which makes them easy to learn.
All parameter names start with a dash, so in this example,
you would type or tab complete ‑DriveLetter.
After the parameter name, you press the space bar,
then type the parameter value.
Now as I mentioned just a moment ago, in some cases,
you might even be able to tab complete the values.
It really never hurts to try.
There are also a few other parameter features that you might encounter.
Now even though I told you about typing the parameter name,
sometimes you don't even have to do that.
So here's a great example.
The Get‑Service command has a parameter called name.
That lets you specify the names of the services that you want to see.
However,
you don't have to include the parameter name. If you
type the command as I've done here, PowerShell will assume that the values,
bits, winrm, and spooler, belong to the name parameter.
The name parameter is called positional, or we refer to it as a positional.
You don't have to type the parameter name.
Some commands have mandatory parameters.
These are parameters that at least require you to enter some value.
These parameters are easy to identify because if you forget something,
PowerShell will prompt you for the missing values.
You'll also learn that many commands, like Get‑Service,
have a default behavior so you don't really have to do anything.
In fact,
you should be able to run just about any command
simply by typing the command name, especially if it is a get command.
If there is a mandatory parameter, PowerShell will simply prompt you for a value.
Otherwise, it will run the command with the default settings.
By the way, if the parameter can take multiple values,
like the names of services here, separate the values with commas.
All PowerShell cmdlets and most functions have a set of common parameters.
One such parameter is ‑Verbose.
Now you can try to include it with any PowerShell command.
If the verbose option has been coded into the command,
you'll see extra information.
This can be very helpful when troubleshooting why a command doesn't work.
However, not every command takes advantage of this feature.
You really won't know if it does until you try.
Now you won't break anything, so just give it a shot.
Another common parameter is ‑WhatIf. This parameter has a very special use
case. You can see the result right here from using ‑WhatIf. When using ‑WhatIf,
the command doesn't actually do anything. Instead,
PowerShell shows you what it would have done if you ran the command
without ‑WhatIf. So this is a great way to check yourself.
This parameter is supposed to be used in any cmdlet that
changes something, like starting a service,
removing a file, or killing a process.
Although you will encounter cmdlets that probably
should support this parameter but don't.
And in those situations, there's really nothing you can do about it other than be careful.