Certifications / Microsoft

PowerShell versus CMD

by Team Nuggets
PowerShell versus CMD picture: A
Follow us
Published on August 12, 2016

If you're in operations, jumping into PowerShell can be intimidating if you have no coding experience. PowerShell is a combination of standard command statements from the old DOS days mixed with some .NET-style syntax.

The frustrating part is that even a .NET coder needs some time to learn PowerShell syntax, because it's unlike any Windows programming or command statements you're used to.

Here are few ways PowerShell is different (and often superior) to standard command line statements.

Cmdlets versus Command Statements

PowerShell is more than just command statements. PowerShell uses functions called "cmdlets." These cmdlets do much more powerful queries and have much better output than you'll find in the Windows command line.

Let's take the simple process of getting an IP address. You can use the ipconfig statement in the Windows command line. This gives you the IP address. Use ipconfig /all and you get all parameters that you need to know about the server including DNS, subnet mask, and the adapter.

With PowerShell, you can use several more input parameters that give you a different level of output. It's probably not necessary if you have a simple server, but PowerShell is an operation's dream for high-level servers. The Get-NetIPAddress cmdlet lets you see IP configuration for both IPv4 and IPv6 and any associated interface. It outputs it to a list, or you can use the Format-Table option to format your output.

That's the one main difference between the two IDEs. You will need to learn cmdlets, and there are far more cmdlets than there are command statements.

Piping Output in PowerShell

One powerful advantage of PowerShell over the command line is the piping mechanism. You can pipe output directly to other commands.

Let's take the simple Get-Service cmdlet. This command shows you the list of services running on a machine. The output is the same as what you would see in the Services window in the Windows control Panel.

You can pipe the output of this cmdlet to a secondary cmdlet to see more information about the list of services. A perfect example is the Get-Member cmdlet.

Type the following into PowerShell:

Get-Service | Get-Member

This command outputs the Get-Service results to the Get-Member cmdlet. Type the cmdlets and notice that the output is entirely different. It gives you the member type and the definition of the service.

Advanced Commands in PowerShell

In the Windows command line, you have the ability to type commands and see output. With PowerShell, you can type a command and then use advanced parameters to search and filter output. One common way to do this is using the Where-Object parameter.

Let's take the Get-Process cmdlet for example. This command shows you all of the processes running on a Windows computer. It's the same output as what you would see if you looked at the list of processes in Windows Task Manager.

Type Get-Process to see the output.

What you'll see is a long list of processes. Several dozen processes run on a Windows server. If you want to find one specific process, it can be tedious. You can find out if a specific process is running by using the Where-Object cmdlet parameter.

Type the following cmdlet into PowerShell:

Get-Process | Where-Object {$_.Name -eq "chrome"}

This command gets a list of processes on the server and then pipes the output to the WHere-Object cmdlet. This cmdlet then lets you search using boolean logic. In this example, the property "Name" must equal (-eq) "chrome." The result shows you all the instances of the Chrome browser running on the machine.

If you perform any daily tasks on a Windows server, PowerShell can be used to automate many of the commands and reports that you run on the server each day. It's also useful to automate file transfers or send analysis reports on server resources. All it takes is some time to understand the way cmdlets work, as well as the cmdlets you have available to you.

Want to learn more about PowerShell? Start training today!

Not a subscriber? Start your free week.


Ultimate Networking Cert Guide

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522