Channel

Command Prompt Vs. PowerShell – A Beginner’s Guide

Author: Dave Long, CTO, Cage Data and Atera Champion
Author: Dave Long, CTO, Cage Data and Atera Champion

Microsoft introduced PowerShell with Windows 7. It is a powerful set of commands for operating system instructions. Scripts written in PowerShell are more like programs than batch files. Find out more about the difference between Command Prompt and PowerShell and how to harness PowerShell to automate admin tasks.

What is PowerShell?

PowerShell is a task automation scripting framework. It includes a command-line shell and a scripting language. It also incorporates the .NET framework. This combination delivers tools to administrators that enable them to automate a lot of their regular daily tasks, while also providing developers with a strong library of functions.

To make .NET processes more accessible, PowerShell incorporates cmdlets (pronounced “command lets”). Think of cmdlets as utilities that can be used in PowerShell scripts. PowerShell ships with a number of cmdlets, but developers can also create their own.

PowerShell easily interfaces with the Component Object Model (COM). This enables the development of more complex PowerShell scripts that can call on many other Windows-based packages to exchange data, issue commands, and receive back statuses.This facility is very useful for developers of applications that utilize PowerShell.

The interface to WMI that is integrated into PowerShell is much more interesting to administrators. Windows Management Instrumentation (WMI) objects are made available as cmdlets. So, it is possible to query the statuses of a device or service running on Windows and incorporate the results into a PowerShell script. This is a very useful status check for conditional processing and branching in a script and it is also a good way to report back on the success or failure of an execution step.

PowerShell vs. CMD

DOS commands are still very useful for moving around the operating system to perform basic tasks. Putting DOS commands into a script to get a series of tasks performed together is still a very common way to create a custom utility. They are frequently used to sequence standard admin tasks so they can be performed as a timed job on a regular schedule out-of-hours.

All of the well-known DOS command line operators and utilities are available in PowerShell. However, the access that PowerShell has to WMI and other system services makes it much more powerful. Think of PowerShell as DOS+.

When should I use PowerShell?

If you are nervous about deploying PowerShell for the first time, just start off with one of your existing batch jobs and look into how to include PowerShell cmdlets to make it work better.

When putting together a simple script for a batch job, you might have thought “If only I could …” Well, the greater capabilities of PowerShell could make that wish come true. The problem most people have with using PowerShell is that it is so big. It makes a lot of experienced administrators feel belittled – like all of their experience has suddenly become out of date. It is a lot more comforting to stick with what you know. Don’t see PowerShell as a threat to your routine, just add on a little at a time and soon PowerShell cmdlets will become as familiar as DOS.

Is PowerShell harmful?

Like any scripting language, PowerShell can be leveraged for malicious activity on computers. There are worms and file-less malware on the internet even now that use PowerShell routines.

To combat some of the threats, Microsoft introduces features in the PowerShell environment; one of which being Execution Policies. PowerShell Execution Policies give administrators control over what scripts can be run on a system. The default policy doesn’t allow for any scripts to be run, but there are also options to require scripts to be signed by a trusted publisher and run unrestricted, allowing any script to run.

Where can I find PowerShell script examples?

This article is an introduction to PowerShell. It opens a series of guides into how PowerShell works and how you can use it. Read through the next chapters in this series to get practical instructions on how to use PowerShell and PSAtera. You will see examples of PowerShell scripts and the most commonly used cmdlets in the following chapters.


Author Dave Long is CTO at Cage Data and an Atera Champion. Read more guest blogs from Atera here.