651.288.7000 info@intertech.com

Introduction to PowerShell

PowerShell is a scripting tool used by IT administrators who manage applications, servers, networks, users, and operating systems. It is task-based, meaning the scripts you run can accomplish many complex and repetitive administrative tasks that would otherwise be complicated, cumbersome, and time consuming to perform without it. This introduction to PowerShell walks you through the basics and helps you get started with the tool.

The Basics

PowerShell is an advanced command line shell, similar in many ways to a Linux or UNIX command line shell. Many of the commands from these OS shells exists in PowerShell, making it an easy transition for UNIX/Linux administrators. Previously, Windows IT administrators were limited to using the DOS Command Prompt, VBScript, COM objects, or a third party shell, such as Bash shell. The classic Command Prompt isn’t nearly as powerful as what UNIX/Linux administrators have had all along. A simple search on the web returns several articles and blog entries specifying the similarities and differences between PowerShell and the UNIX/Linux shells.

Versions

Because PowerShell tasks are so closely related to certain versions of the Windows operating system and the types of tasks that can be performed on them, only certain versions of PowerShell are supported with the different versions of Windows. Note that PowerShell has been included with the latest versions of Windows. As well, it has since been packaged as being a major component of the Windows Management Framework (WMF), used by IT administrators.

Currently, there are five different versions of PowerShell, with Version 4 being the latest “officially released” edition. There is a public preview version available for version 5 that can be downloaded today as part of the WMF.

Version 1 was released in 2006 for Windows XP SP2, Windows Vista, and Windows Server 2003. It was also an optionally installed feature of Windows Server 2008.

Version 2 was a huge upgrade for PowerShell in 2009. It included many new features and a new Integrated Script Environment (ISE 2.0) for writing script. It is available for download for the older operating systems. It was also included with Windows 7 and Windows Server 2008 R2. Version 2 has since been rolled in to be a part of the Windows Management Framework, which includes Windows PowerShell 2.0, Windows Remote Management 2.0 (WinRM), and Background Intelligent Transfer Service 4.0 (BITS).

Version 3 was a minor upgrade and was included with Windows 8 and Windows Server 2012. It was made available for download for Windows 7 and Windows Server 2008 (R2). It was also included with the larger management pack Windows management Framework 3.0 (WMF3).

Version 4 is the current version of PowerShell. It was included with the release of Windows 8.1 and Windows Server 2012 R2. It is also available for download for Windows 7, Windows Server 2008 R2, and Windows Server 2012.

Version 5, including WMF 5.0 and PowerShell ISE was released as a technology review version in May, 2014. It is available here: http://www.microsoft.com/en-us/download/details.aspx?id=42936

Starting PowerShell

PowerShell can be launched in various ways. From the Start screen, a user can simply start typing “powershell” to start the command window. Note the user should be cautious because it will not automatically start with administrative privileges, without right-clicking it and choosing to do so.

Launching PowerShell in Windows 8.1

Launching PowerShell in Windows 8.1

The window will appear with the Administrator account appearing in the title bar. Note the “PS” prefix to the left of the command prompt, reminding us that we are in PowerShell – not the normal Command Prompt.

The PowerShell Console

The PowerShell Console

All of the classic DOS commands will work in PowerShell, including many of the commands you may have used in UNIX/Linux shells. For example, you can perform a “DIR” listing as well as an “ls” listing. In UNIX/Linus, you may have used a “grep” command to search for text within a document. In PowerShell, you can use the “Select-String” command. For those with experience with the classic shells, learning PowerShell commands will be required to make the transition easier. There is a great chart comparing the commands of the Command Prompt, PowerShell, and UNIX shell here: http://en.wikipedia.org/wiki/Powershell#Comparison_of_cmdlets_with_similar_commands

Cmdlets

Before PowerShell was released, most IT administrators used VBScript to manage their network. PowerShell has the power of the entire .NET framework. It is largely made up of task-based commands called cmdlets (pronounced “command-lets”). Scripts can be created that include calling cmdlets. Many cmdlets were released by Microsoft for managing their server products including Windows Server, Microsoft SharePoint Server, Microsoft SQL Server, Microsoft Exchange Server, and more. As well, many third party developers have also created custom cmdlets for their products such as IBM WebSphere and VMWare. Custom cmdlets can be created using C# or VB.NET.

Cmdlets take on a naming convention based on a “verb-noun” naming convention, with a hyphen always being used between the verb and the noun. For example, if you would like to learn more about the “Select-String” cmdlet, you can use the “Get-Help” cmdlet, like this:

PowerShell's Grep

PowerShell’s Grep

There are many “core” cmdlets available. You can see a list of the core cmdlets here:

http://technet.microsoft.com/en-us/library/hh849695.aspx

Besides cmdlets, there are also functions that can be called from scripts and modules. You can find all the functions, modules, and cmdlets installed on your machine by opening a PowerShell window and typing “Get-Command”.

Capture

Integrated Shell Environment (ISE)

Scripts can be created to combine several PowerShell commands together. Starting with PowerShell 2, Microsoft released a new editor called the Integrated Shell Environment (ISE) that allows the developer to develop, edit, and debug PowerShell scripts. PowerShell scripts use the “*.ps1” file extension.

ISE can be launched from within PowerShell by simply typing “ISE” and hitting <Enter>. Alternately, it can launched from the Start screen by simply typing ISE, or even from a classic Command prompt by typing “PowerShell_ISE”.

When launched, it will start a script editor that can be used to edit and debug your PowerShell scripts, PowerShell modules, and PowerShell data files. Besides giving you an editor with color coding and auto-completion (IntelliSense), it also includes a PowerShell window near the bottom. Custom Add-ons can also be installed in ISE for unique functionality.

There are several PowerShell scripts already installed on your machine. If you do a simple search for *.ps1 files on your hard drive, you will find several management files. Here is ISE with one of Microsoft’s included scripts for managing IE Browser add-ons.

The ISE

The ISE

Web Sites

Usually, learning PowerShell has been out of necessity by administrators but it should be considered a very powerful tool in every administrator’s toolbox. Some tasks can only be performed using PowerShell when managing Windows or servers. Along with this introduction to PowerShell, there are several web sites available to help you get started including tutorial sites to help you learn it. Here are just a few of them. Good luck and best wishes.

The main PowerShell site:

http://www.microsoft.com/powershell

Microsoft Script Center:

http://technet.microsoft.com/en-us/scriptcenter

Windows PowerShell Team Blog:

http://blogs.msdn.com/b/powershell/

Microsoft Virtual Academy PowerShell training:

http://www.microsoftvirtualacademy.com/Studies/SearchResult.aspx?q=powershell

Like What You've Read?

Subscribe to the Blog.

Every Friday we send that week's content from our Developers via email. Try it out!

Some ad blockers can block the form below.

You have Successfully Subscribed!

Pin It on Pinterest

Share This