Why You Need to Learn PowerShell

The command line scares Windows administrators, and that’s no surprise considering that Windows was created as the antithesis to Unix, and other CLI operating systems deemed unusable by mere mortals. But the only way to truly harness the power of Windows Server and Microsoft Azure is to embrace Windows PowerShell.

What is PowerShell?

PowerShell is a task-based command-line shell and object-orientated scripting language based on the .NET Framework. As such, PowerShell provides the ability to automate complex system administration tasks, albeit at the expense of a mild learning curve. Cmdlets provide access to the operating system and applications for performing configuration and management tasks, and an extensible interface allows third-parties to build their own PowerShell modules.

Why you need to learn PowerShell Windows PowerShell cmdlets like Get-Content can simplify many IT configuration and management tasks. (Image: Jeff Hicks)

PowerShell can be compared to Python, which is the most common scripting language for Unix-based OSes. The capacity to perform advanced object manipulation and pipe the results to other cmdlets or applications, allows IT to automate tasks more easily than was possible with VBScript.

The PowerShell Learning Curve

I once considered myself a VBScript and Windows Script Host (WSH) guru and took pride in being able to automate complex tasks. I haven’t written a VBScript for years and adopted PowerShell more slowly than I should have, but it was clear from the beginning that PowerShell is superior to simple DOS commands or VBScript. Many of the failings of VBScript, such as the inability to detect that a task has completed successfully before executing the next line of code, are dealt with by PowerShell gracefully.

Using PowerShell to configure a virtual machine on Microsoft Azure

Using PowerShell to configure a virtual machine on Microsoft Azure. (Image: Russell Smith)

PowerShell’s object-orientated approach sometimes makes it difficult to discover the required cmdlet, function or object. Moreover, Azure is changing at such a fast pace with Microsoft announcing new features and improvements at least once a month. As a result, it’s hard to keep up with all the new functionality and changes to the Azure platform. Nevertheless, anyone who is experienced in VBScript should be able to master PowerShell relatively quickly.

Is PowerShell Secure?

VBScript and WSH got a bad rap for exposing OS vulnerabilities that were leveraged by malware authors to compromise Windows computers. Add to that the potential for a few lines of code to wreak havoc if not properly tested, or if run maliciously, and the ‘power’ in PowerShell might start to look less attractive.

PowerShell was built from the ground up with security in mind. Along with script execution policies, the ability to digitally sign scripts, and create constrained endpoints that limit access to PowerShell not only to specific groups of users, but also the cmdlets they have access to, there’s no inherent risk in using PowerShell as long as best practices are followed and built-in OS security mechanisms are enabled.

PowerShell in Practice

A couple of years ago I was considering employing some part-time help to manage my lab deployments. At that point I hadn’t fully embraced the cloud, and I was using my office Hyper-V server with a bit of help from VMware on two workstations. It was a mess, time consuming to manage and was gnawing away at my billable time.

Then Azure started to shape up as a viable alternative to Amazon Web Services (AWS), and as a Microsoft technology based on Windows Server 2012 and Hyper-V, it wasn’t something I could ignore. Having initially been scared off by what seemed like a steep learning curve, and a brief flirtation with CloudShare — a service primarily aimed at developers — all my testing requirements are now handled by Azure.

A High Return on Investment

Although there are many advantages to the cloud, spinning up new environments is still a time-consuming process if one has to rely on Azure’s web-based management portal. Despite being no stranger to PowerShell, I was reluctant to invest time in creating scripts to automate common tasks after having seen some complicated recipes that suggested it might be a daunting mission.

I’m glad to report that following a few days of hard labor in front of my notebook, I have reduced the time it takes to deploy entire Windows Server environments on Azure from hours to just minutes. Not only has PowerShell removed the need for me to rely on someone else to help out, but the frustration of having my concentration broken, by having to constantly check the status of servers as they’re being deployed, leaves me free to work uninterrupted.

Learn PowerShell Now

If you’ve yet to take a serious look at PowerShell, I seriously encourage you to do so. The best way to learn is by example, of which there are plenty on Petri, starting from the most basic use of cmdlets to more sophisticated scripted solutions. See Perform 7 Essential IT Management Tasks with PowerShell by Blair Greenwood and Is PowerShell the Future of Windows Server Management? to help you get started.