How to use parameters to add values in Windows PowerShell

How to use parameters to add values in Windows PowerShell

Learn how to use parameters to add values in Windows PowerShell. This video is part of a full training course called PS300: PowerShell for Administrators online Video Training

To help introduce Interface Video Training, the first 13 videos in this PowerShell training course are available for free below. The entire Video Training Library is available for only $25 per month.

Instructor: Don Jones, Microsoft MVP
Video Style: Screencast
View the entire PowerShell for Administrators Course


PowerShell Online Video Training


Video transcript:
PowerShell – Use Parameters to add Values

We’ve got to get some gotchas out of the way. I’ve been throwing a lot of syntax at you. If you don’t have a lot of experience with command-line interfaces, this is where it’s easy to get lost. So, to find ourselves, let’s get rid of the command-line interface entirely. Go back into Active Director Users and Computers. Let’s find a User here, pop this open and take a look at it.

This is a pretty common Windows dialog box.

You’ll find you’ve got parameter information in here, so every one of these has got a little label.

We’ve got Betty’s First name, Last name, Display name, Description, Office and so forth. Those are typically accompanied by a place to provide information. In this case, it’s a text box. This is where you type the information that goes with this. Betty is the First name, Slater is the Last name, Betty Slater is the Display name, Engineering User is the Description and so forth.

This lines up exactly to what PowerShell does. So let’s get rid of this and hop back into the shell.

If I were to run a command, such as something where we can play with services, like new-service, Help New-Service.

Just look at the syntax here. You’ll notice that there’s a lot of parameters. There’s -Name, there’s -Credential, there’s -DependsOn there’s -Description.

This looks like the graphical interface if you think about it.

New-Service –Name MySpecial Service –Description ‘This does something cool’

Watch this pattern.

It starts with the parameter name. The parameter name always has a dash in front of it. After the parameter name, there’s a space and then the value of that parameter.

After the value is a space, and then a dash starts the next parameter. It’s dash, name, space, value. Let’s all say that together, dash, name, space, value. It seems silly, but it’s designed to remind you how this pattern goes.

What you don’t want to do is get into the habit of typing New-Service –MyCoolService. There’s no parameter called MyCoolService. What you’re probably trying to do is specify the name, and then the string that goes with the name is MyCoolService.

In fact, making sure that your commands look a lot like the Help, will help you avoid mistakes that newcomers to PowerShell make. Dash, name space, value, that’s what’s in the Help file, dash, name, space, value. That’s what I typed, so it will probably work just fine.

The other thing you’ll run into that’s kind of a gotcha – and this is probably my fault for doing this to you. You’ll see folks type New Service.

And that’s because folks that are familiar with PowerShell, will talk about commands that way. They’ll say, Get Service.

In reality, all PowerShell commands have a dash between the verb, Get, and the noun, Service,

get-service

Or

get-process

I guess we should all say get, dash, process and get, dash, service, but we don’t. That’s one of the things you’ll have to get used to.

If you find yourself typing that space in there (between Get and service), you’re wrong. It’s all got to run together with that dash in the middle.

So getting those command names and getting those parameter value name patterns is really critical. It’s how every single PowerShell command works.

The good news is it’s how every single PowerShell command works. You only have to get this through your head once. Once you wrap your hands around it and you get used to working with it that way, you’re finding that everything works that way. You only need that one pattern.   

 

More online training videos from Interface Technical Training.

For Instructor-Led live classes, see our complete Course Schedule. Many courses are available online with RemoteLive™.

 

Posted in PowerShell | Posted in , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">