Windows PowerShell Cmdlet
PowerShell Tutorial 2: PowerShell Commands – Cmdlet
The concepts in this tutorial have come from my readings of Bruce Payette's book – Windows PowerShell in Action. Bruce is a founding member of the PowerShell team and is a co-designer of the PowerShell language. His book is highly recommended and has been made available from this site. Who better to learn about PowerShell than from the designer himself!
There are four categories of PowerShell commands: Cmdlet (Command-Let), PowerShell Functions, PowerShell Scripts, and native Windows commands. Each category will be examined in tutorials on this site. Lesson 2 focuses on the PowerShell cmdlet, so let's get started…
cmdlet – naming convention
There are over a hundred new PowerShell commands to learn, but no need to panic. Unlike most other command-line interfaces, PowerShell commands have been standardized using a "verb-noun" naming convention know as a cmdlet. This standard simplifies the learning curve and provides a better description of what the cmdlet does. To see a list of cmdlets available in PowerShell type the following cmdlet:
Note: <enter> denotes typing the Enter/Return key on your keyboard.

Image 2.1
The "Name" column lists the cmdlets in the "verb-noun" naming convention.
Next, let's list all the commands that use a specific verb. The following command yields all cmdlets that use the verb "Get."

Image 2.2
Play around with the -Verb parameter, try finding commands that use the verbs; Add, Clear, New, and Set.
Getting commands that use specific nouns is just as easy. Type the following command to see which cmdlets use the noun "Service."

Image 2.3
Just as it sounds, the verb describes an action and the noun describes the "what" to take the action against. One thing I want to mention before moving forward, the PowerShell command line is not case-sensitive. In PowerShell – "get-service" or "Get-Service" or even "GeT-SerVIce" is the same command.
Getting help
In learning new technologies, it is important to find information quickly and easily. Get-Help cmdlet has been designed for that purpose; this will be the most utilized cmdlet until you become more proficient.
Get-Help Examples:
Information about Get-Help cmdlet. Includes description, syntax, and remarks.
Information about all available help topics.
Information about a specific cmdlet.
Two other forms of the Get-Help cmdlet exist, the noun "Help" and the "-?" parameter. Help, by itself provides the same info as Get-Help *. Use Help with a cmdlet as follows, Help Get-Service. With the help parameter, Get-Service -?. The Scripting Guys created a graphical Help file which is available on this site. Located in the Categories -> PowerShell Downloads -> PowerShell Graphical Help File. The Graphical Help file is great tool for learning and reference, I recommend downloading it.
Using cmdlets
In this section I will be using Service to demonstrate cmdlets. Image 2.3 lists eight cmdlets associated with the noun Service: Get-Service, New-Service, Restart-Service, Set-Service, Start-Service, Stop-Service, and Suspend-Service. Not only will we be running cmdlets from the PowerShell command line, I'm also going to explain it graphically. O.k. that sounds kind of graphic… what I mean is I'm going to describe the equivalent action taken when working in GUI tools. I find this a tremendous help when attempting to understand new concepts.
What services are on the computer? Type the following cmdlet:

Image 2.4
You should now have a list of services on the computer as well as their status, similar to the list above. Which GUI tool gives us the same information? The Services MMC (Microsoft Management Console). Launch the Services MMC from Start -> Programs -> Administrative Tools -> Services. If Administrative Tools are hidden from the Programs Menu, you can launch it by typing services.msc from the PowerShell command-line. As stated earlier, one of the PowerShell command categories is "native windows commands." This is how we are able to launch services.msc from the PowerShell command-line.

Image 2.5
Exercise 1: Stopping and Starting a Service.
For this exercise I will be using both the Stop-Service and Start-Service cmdlets. To demonstrate, I have chosen the "Computer Browser" service for this example. The current status of the Computer Browser service is "Started" and the "Status Type" is "Automatic." For this exercise it is important that you choose a service that has a status type of either automatic or manual. If you choose a service with a status type of disabled, this exercise will not work.
The following syntax stops a service: Stop-Service [-name] or Stop-Service [-displayName]. This is not the complete syntax for the Stop-Service cmdlet. If you want to see the full syntax, use the Get-Help cmdlet as discussed earlier. To begin, let's show the status of the Browser Service. Then Stop it using the Stop-Service cmdlet. Lastly check the status. Type the following cmdlets:
Stop-Service -name Browser <enter>
Get-Service -name Browser <enter>

Image 2.6
Note: When you run the Stop-Service cmdlet there is no indication that the service has actually stopped. This is why I ran the Get-Service command to verify the status changed to "Stopped."
We should see the same change in the Services.msc GUI. In the GUI a Status of "Blank" means "Stopped."

Image 2.7
The following syntax will start a service: Start-Service [-name] or Start-Service [-displayName]. Look familiar? Again, let's check the status, start the service, and verify the status has changed.
Start-Service -name Browser <enter>
Get-Service -name Browser <enter>

Image 2.8
Check the GUI, the status of Browser should be "Started" (make sure to refresh the view).
This exercise should give you an indication of the benefits of using PowerShell. With just a couple of cmdlets we were able to stop and start a service. Traditionally, an Administrator would launch the GUI, select the service, and then either stop or start it. Doesn't seem like a big deal until you are asked to stop a service on multiple computers. Through PowerShell Scripting you will be able to start, stop, and change status types of a service on multiple computers without much effort. Write a script, run-it, and then kick you feet up on the desk.
This tutorial has introduced the PowerShell naming convention, cmdlets, getting help, and an example of using the Service cmdlet. As stated before, there are over a hundred cmdlets in PowerShell. This should be enough to keep you busy for awhile. See you in the next tutorial where we will be covering PowerShell Aliases.
Email This Page To A Friend
Comments
Fab tutorial, I will be completing the rest of the series.
Top Dude
Great tutorials so far! Thanks a bunch!
One suggestion though, you should put links at the bottom to jump to the next chapter. Thanks again!
Keep up the Good work.
Thanks MVP!
Great tutorial…Keep it coming..the link idea is a good one.
You can already start and stop services from the command line without Powershell. It’s “Net Stop [service]” and “Net Start [service]“. Put it in a batch file and push it out using your favorite app pushing service in Active Directory or eDirectory.
A good way to teach something new, is to relate it to something already known. Stopping and starting services is a great example.
Hi everyone,
i just found out something in the PowerShell console. Try this:
Type Get-Command -Verb G and now press *TAB*…The Word *Gentleman* appears!!!
Anyone has any idea what this is? An easter egg?
> Kiran : I don’t think so. Perhaps you have something named “Gentleman” in your working directory…
You might want to mention that on Vista we need to run Powershell as administrator for the service example to work unless i am missing something..
“The Scripting Guys created a graphical Help file which is available on this site. Located in the Categories -> PowerShell Downloads -> PowerShell Graphical Help File.”
You should make use of HTML’s hyperlinking feature more often. It’s fabulous!
Great post,
Keep up the good work
Thanks
Hi
Thanks for the great efforts to teach us!
Appreciate it !!!!
Regards
Kristof
Thanks and thanks again,
Taking familiar tasks and showing how its done in powershell is a great idea.
Keep up the GREAT work!
Thanks for a great job. I do have a question: I’m running a beta of Win 7. the “start-service” and “stop-service” don’t seem to work, any idea what could be stopping this?
John, right-click on Powershell icon and choose to “Run as Administrator”. That might fix your problem. Unless you do that, Powershell console will be running with standard user privileges.
Thanks for this terrific guide.
I’m not a natural programmer, but I’ve made more progress going through this guide than I have in weeks through reading the usual books.
EXCELLENT stuff – many thanks!
Hi, this is very helpful tutorial – easy to follow and understand. Thank you! However, the TOC on the right does not work – when I click on the links from top (conditional logic) – then it jumps to tutorial#8, instead of tutorial #3. It would be helpful to have the link to the next tutorial at the bottom of each tutorial. Thanks again!
I have problem using following commands to find the status of service. For some of the services its not working
ex: get-service -name clipbook
get-service -name DHCP client
anybody have any idea why these cmdlets not working on my windows 2003.
I found the answer for my questions..
thank you
tutorial is awesome
This is a really excellent guide to PowerShell. You have a gift for explaining technical concepts. Well done, and please keep up the good work
Thanks for the tutorials. There aren’t too long and I do like the way you explain things.
Could not get the exercise to work with Windows7.
Hi,
Please specify what version of powershell the tutorial is for. Thank you.
Excellent PS tutorial for this beginner. Thanks
Works with Win7 if you start PS with RunAs Administrator
can we get the service status for a remote server?
hi,
its a gr8 tutorial and it is very helpful for beginers like me.
Superb! cheers for a great tutorial.
Thanks for this great powershell tutorial. If you are a beginner, this is the place to start!
thanks for the great tutorial
Wow! what a great article you wrote I’m just getting the feel of powershell.
Great tutorial. Very easy to understand. Seemed to have trouble opening my computer’s browser service though. It was stopped by default and when I tried to start it, got an error: Cannot open browser service on computer ‘.’. Perhaps it’s because my machine is so tightly managed. I’ll try some other services.
Great Tutorial. Great way to learn new skills. However, I am having problem stopping any service on my PC. Every time I tried , igot the following error message: Get-Service : Cannot find any service with service name ‘theme’.
At line:1 char:12
+ get-service <<<< -name theme
+ CategoryInfo : ObjectNotFound: (theme:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand"
Sorry for the long error message. But Can any one help me figure this out?
Cheers
Gerard , the service name should be themes not theme , with S
I want to create users from imported file of Excel and want to give the user name but I want to join last name and first name of user with just two character.
Example Hardik -first name
Patel – last name
I want to give HardikPa(this type of name ) to all users
Thanks so much for this, but i have a question, which is off the wall from the subject you have mentioned: how can I start more than one process? I’ve tried this:
start-service browser works, but start-service browser, branchcache didn’t work.
Like start-process notepad works, but start-process notepad, wordpad didn’t work.
Thanks so much in advance.
This is the best tutorial I’ve come across on this topic. Good job!!
Power shell command to get a list of machines from an OU whose member of does not contain XYZ group.
The below command gives me the list of machine from the OU whose memberof is XYZ group.
Get-ADComputer -searchscope onelevel -SearchBase “OU=Desktops,DC
=test,DC=com” -filter {memberof -eq “CN=XYZ,DC=test,DC=com”}
I am trying to get the reversal of this result.. The result should give me result of machines whose memberof does not have XYZ group… Please help on this..
Thanks
Rinson
@Rinson
Get-ADComputer -searchscope onelevel -SearchBase “OU=Desktops,DC
=test,DC=com” -filter {memberof -neq “CN=XYZ,DC=test,DC=com”}
I had some troubles getting services to start and could not figure out why… Turns out I had to run PS as a Administrator (right-click, “run as administrator”) in Windows 7. Helpful tip for newbies like me.
I have a question though, for the life of me I cannot get the “fax” service to start through Powershell. I can start it in the GUI, and I can then also stop it PS. But I always get an error trying to start it. It is set as “manual” start -up type, not disabled. The error is as follows: Start-Service : Service ‘fax (Fax)’ start failed.
At line:1 char:14
+ Start-Service <<<< fax
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand
Any help in why I get this?
Amazing tutorial thus far. I figured it was time to learn this, and I thought I would hate it. However, this tutorial is engaging, which is key in any learning process.
Should have seen this tutorial back in 2008! But as they say, it’s always never too late to learn
Now I can upgrade my knowledge on VBScripting, WSC and WSH.
Good Job! Author.
I enjoy the way you keep things simple to understand without getting to technical. This allows one to ease into the subject and gain confidence. You are a good teacher.
Wow thanks for the help. Its very help full to work with service in non english build.:D
Are there universal switches other than
“-?” that work with cmdlets? Similar to “/p” (for pause) or “/o” (for order)?
is there a way to do a Get-service and filter only those that are either “running” or “stopped”?
excellent article.. Gave me a great introduction to cmdlets which other sites dint provide. thank you.
Great site! I just started a job in IT and I had never even heard of Powershell.
Thank you so much for all you have done!
-Sean
Leave a Comment