The difference between PowerShell and Command Prompt

PowerShell is very different from the Command Prompt. It uses different commands, known as cmdlets in PowerShell. Many system administration tasks – from managing the registry to WMI (Windows Management Instrumentation) – are exposed via PowerShell cmdlets, while they aren’t accessible from the Command Prompt.

Set-Location C:\

PowerShell makes use of pipes, just as Linux and other Unix-like systems do. Pipes allow you to pass the output of one cmdlet to the input of another cmdlet, using multiple cmdlets in sequence to manipulate the same data. Unlike Unix-like systems, which can only pipe streams of characters (text), PowerShell pipes objects between cmdlets. This allows PowerShell to share more complex data between cmdlets.

PowerShell isn’t just a shell you use. It’s a powerful scripting environment that can be used to create complex scripts for managing Windows systems much more easily than you could with the Command Prompt.

When You Would Want to Use PowerShell

So you’re an average Windows user – when would you want to use PowerShell? Well, if you rarely use the Command Prompt and fire it up to run the occasional ping or ipconfig command, you’ll probably never need to touch PowerShell

PowerShell can be a much more powerful command-line environment than the Windows command prompt. For example, we’ve shown you how to use the PowerShell environment built into Windows to perform a search-and-replace operation to batch rename multiple files in a folder – something that would normally require installing a third-party program. This is the sort of thing that Linux users were once able to do with their command-line environment, while Windows users were left out.

dir | Rename-Item -NewName {$_.name -replace ",","."}

However, PowerShell isn’t like the Linux terminal – it’s a bit more complicated, and the average Windows user won’t see many benefits from playing with it.

System administrators will want to learn PowerShell so they can manage their systems more efficiently. If you need to write a script to automate various system administration tasks, you should do it with PowerShell.

PowerShell Equivalents of Common Commands

Many common Command Prompt commands – from ipconfig to cd – will work in the PowerShell environment. This is because PowerShell contains “aliases” that point these old commands at the appropriate new cmdlets, running the new cmdlets when you type the old commands.

We’ll go over a few common Command Prompt commands and their equivalents in PowerShell anyway – just to give you an idea of how PowerShell syntax is different.

Change a Directory

  • DOS: cd
  • PowerShell: Set-Location

List Files in a Directory

  • DOS: dir
  • PowerShell: Get-ChildItem

Rename a File

  • DOS: rename
  • PowerShell: Rename-Item

To see if a DOS command has an alias, you can use the Get-Alias cmdlets. For example, Get-Alias cd shows you that cd is actually running the Set-Location cmdlets.

Get-Alias cd
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s