cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post

POwerful SHortcut to Automating Operations

Level 12

A few years back I was working at a SaaS provider when we had an internal hackathon. The guidelines were simple: As part of your project you had to learn something, and you had to choose a framework/methodology beneficial to the organization. I was a Windows and VI admin, but along with my developer friend, we wrote an inventory tool that was put into operational practice immediately. I learned a ton over those two days, but little did I know I’d discovered a POwerful SHortcut to advancing my career as well as immediately making my organization’s operations more efficient. What POtent SHell could have such an effect? The framework I chose in the hackathon: PowerShell.

A Brief History of PowerShell

Windows has always had some form of command line utility. Unfortunately, those tools never really kept pace and by the mid-2000s, a change was badly needed. Jeffrey Snover led the charge that eventually became PowerShell. The goal was to produce a management framework to manage Windows environments, and as such it was originally used to control Windows components like Active Directory. The Microsoft Exchange UIs were even built on top of PowerShell, but over time it evolved into way more.

Today, one of the largest contributors to the PowerShell ecosystem is VMware, who competes with Microsoft in multiple spaces. Speaking of Microsoft, it’s shed its legacy of being walled off from the world and is now a prolific open-source contributor, with one of their biggest contributions being to make PowerShell open-source in 2016. Since being open-sourced, you can run PowerShell on Mac and Linux computers, as well as for managing the big three (AWS, Azure, Google Cloud) cloud providers.

Lots of People Are on Board With PowerShell, But Why Do YOU Care?

In an IT operations role, with no prior experience with PowerShell, I was able create a basic inventory system leveraging WMI, SNMP, Windows Registry, and PowerCLI, amongst others. I mention this example again because it demonstrates two of the most compelling reasons to use PowerShell: its low barrier to entry and its breadth and depth.

Low Barrier to Entry

We already determined you can run PowerShell on anything, but it’s also been included in all Windows OSs since Windows 7. If you work in an environment with Windows, you already have access to PowerShell. You can type powershell.exe to launch the basic PowerShell command window, but I’d recommend powershell_ise.exe for most folks who are learning, as the lightweight ISE (Integrated Scripting Environment) will give you some basic tools to troubleshoot and debug your scripts.

Once you’re in PowerShell, it’s time to get busy. The things performing work in PowerShell are called cmdlets (pronounced command-lets). Think of them as tiny little programs, or functions, to do a unit of work. If you retain nothing else from this post, please remember this next point and I promise you can become effective in PowerShell: all cmdlets take the form of verb-noun and if properly formed, will describe what they do. If you’re trying to figure something out, as long as you can remember Get-Help, you’ll be OK.

Here’s the bottom line on having a rapid learning curve: there are a lot of IT folks who don’t have background or experience in writing code. We’re in a period where automation is vitally important to organizations. Having a tool you can pick up and start using on day one means you can increase your skill set and increase your value to the organization easily. Now if only you had a tool that could grow with you as those skillsets evolved…

Depth and Breadth

At its most fundamental level, automation is about removing inefficiencies. A solution doesn’t need to be complex to be effective. When writing code in PowerShell, you can string together multiple commands, where the output of one cmdlet is passed along as the input of the next, via a process called the pipeline. Chaining commands together can be a simple and efficient way to get things done more quickly. Keep in mind PowerShell is a full-fledged object-oriented language, so you can write functions, modules, and thousands of lines of code as your skills expand.

So, you can go deep on the tool, but you can go wide as well. We already mentioned you can manage several operating systems, but software across the spectrum are increasingly enabling management via PowerShell snap-ins or modules. This includes backup, monitoring, and networking tools of all shapes and sizes. But you’re not limited to tools vendors provide you—you can write your own. That’s the point! If you need some ideas on how you can jumpstart your automation practice, here’s a sampling of some fun things I’ve written in PowerShell: network mapper, port scanner, environment provisioning, ETL engine, and web monitors. The only boundary to what you can accomplish is defined by the limits of your imagination.

What’s Next

For some people, PowerShell may be all they need and as far as they go. If this PowerShell exploration just whets your appetite though, remember you can go deeper. Much of automation is going toward APIs, and PowerShell gives you a couple of ways to begin exploring them. Invoke-WebRequest and Invoke-RestMethod will allow you to take your skills to the next step and build your familiarity of APIs and their constructs within the friendly confines of the PowerShell command shell.

No matter how far you take your automation practice, I hope you can use some of these tips to kickstart your automation journey.

13 Comments
MVP
MVP

Thanks for the info, I didn't realise it was open source.

MVP
MVP

Thanks for the write up.

Level 12

I find myself spending a lot of time debugging Powershell because I put a bunch of Bash into the code. Old habits die hard.

Level 12

Happy to share! Microsoft is still struggling to shake off their historical legacy as being walled off from the world, but IMHO the really have turned a corner with their approach to open source

Level 12

Thanks for reading!

Level 12

Ha! I know where you are coming from! That inventory project also called a bunch of external VBscript. Guess where I spent most of my time debugging? Once I started converting to PoSH my scripts became more resilient and actually simpler as well.

But hey, whatever tool works for the job! If bash is your jam, then rock it proudly!

Thanks for sharing!

MVP
MVP

PowerShell seems to be the wave of the future in the Microsoft world (OK, it's been around quite a while, but some are still gathering to it) and in this case they use their own product a lot. Many, many functions in the newer O/Ss are implemented via PowerShell scripting.

I got into the hardware side of things to avoid programming, but with PowerShell it seems programming has to be back on the table.

Level 12

I'd recommend giving scripting a shot. I personally find it a lot of fun.

To your point, PowerShell definitely isn't going away. Those who can easily harness the power it provides, IMHO have the chance to step ahead of the pack.

Level 13

Thanks for the article

Level 12

Thanks for reading along

Level 13

Thanks for sharing.  For years the biggest gripe I had about Windows was the lack of a really robust and useful scripting language.  You can get so much accomplished so much more quickly than by clicking and navigating through a bunch of windows.  It really is transformative.

Level 12

I couldn't agree more!

Level 12

thanks for the post

About the Author
https://virtualvt.wordpress.com/ https://twitter.com/VTsnowboarder42 https://www.linkedin.com/in/scott-driver42/