Getting Started with PowerShell
Regardless if you're a system administrator, developer, cloud engineer or data center guru, you can benefit from automation. Automation saves tons of time and removes us error-prone humans from important production tasks.
Scripting is a great way to automate thousands of tasks across nearly every facet of our infrastructure and development work. One popular scripting language capable of managing and automating just about everything is PowerShell.
PowerShell has transformed the way thousands of us get work done. It has given us an intuitive language capable of being used by a junior help desk technician all the way up to a seasoned software developer. But, unfortunately, there are still a lot of sysadmins out there that haven't caught on yet.
Let's change that.
We are starting a blog post series here at Skylines Academy called Getting Started with PowerShell. This series aims to introduce core concepts and fundamentals of PowerShell to springboard system administrators into automating with the language.
The series will be a set of blog posts that teach the fundamentals of writing PowerShell through as many real-world applications as possible.
The series is aimed at system administrators, cloud engineers or anyone in IT that's tired of manually performing routine tasks and is ready to learn how to write PowerShell scripts.
By the end, you will have a solid, foundational knowledge of PowerShell and how to get started using it in your day-to-day work life. You'll come away with enough PowerShell skills that will spark ideas and inspire you to begin writing PowerShell on your own.
Table of Contents
The series will be broken into 12 blog posts each cumulatively building upon the next. Although you're welcome to digest posts in any order you choose, to get the most of this "blog post course", we encourage you to start from the beginning.
Windows PowerShell, PowerShell Core and PowerShell: Huh?(Publish date 3/5/20)
Many admins are still using Windows PowerShell and not PowerShell (Core) because they don't know why they should switch. This will be less of a how-to article and more of a post helping admins understand the difference, how to "convert" Windows PowerShell scripts to work with PowerShell and why they should switch to PowerShell.We'll also cover some technical ground using the WindowsCompatibility module.
Installing PowerShell and Visual Studio Code (Publish date 3/26/20)
PowerShell does not come pre-installed as Windows PowerShell does. To write and edit scripts, Windows comes with the PowerShell ISE editor but is now considered legacy. Instead, we recommending using the free code editor called Visual Studio Code. You'll need both to leverage PowerShell (and this series)l to the fullest extent.This post will outline how to install both products and perform any initial recommended configuration to get hit the ground running.
Running PowerShell Commands and Getting Help (Publish Date 4/10)
We'll open up the PowerShell console for the first time and cover the concept of a cmdlet. We'll go over how to run commands, the verb/noun syntax for PowerShell commands and other basic information about running commands in the PowerShell console.This post will also cover the
Get-Help
command and show you how to find all of the built-in help content.Working with the PowerShell Pipeline (Publish date 4/30)
The pipeline is one of the most unique and useful features of PowerShell. The pipeline allows you to seamlessly pass objects instead of strings like Bash and other shells do. Don't worry if that doesn't make sense now; it will by the time you're done with this post!
Writing Your First PowerShell Script (Publish date 5/14)
It's time to step away from the console and start combining commands in a script. In this post, we'll show how to put commands in a script and run them all as one. This post is where that Visual Studio Code editor you installed comes into play.
This post will start the "project-based" posts. This and every other post from here on out in the series will build a simple tool the reader can build and use in their environment.
Understanding Loops in PowerShell Loops (Publish date 5/4)
One common construct you'll use in PowerShell is loops. Loops allow you to process collections of things - not just a single thing. Even in the simplest scripts, you'll need to learn loops.
In this post, you'll create a script with some great examples on using foreach loops, for loops, do/until and do/while loops.
Using PowerShell Modules (Publish date 6/29)
This post will cover what a PowerShell module is, their purpose and how to work with them. It will cover how to download modules from other locations like the PowerShell Gallery and use commands inside. It will not cover how to create modules. We might cover that at another time.
Connecting to Azure (Publish date 7/21)
PowerShell, after all, is an ends to a means. No one creates a PowerShell script just for fun. That script must do something. In this post, you'll learn how to use the Az PowerShell module to connect to Azure and perform some simple tasks. You'll learn how to use the
Connect-AzAaccount
module to authenticate to Azure and build a simple script to demonstrate what's possible with the Az PowerShell module.PowerShell Error Handling (Publish date 9/9)
Even though you can write PowerShell without error handling, it's not smart. To write professionally-built scripts that remain robust and can handle unexpected errors, you must implement some form of error handling.
This post will introduce the concept of error handling in PowerShell, cover the difference between soft and hard-terminating errors, explain what exceptions are and how to build try/catch blocks in scripts to ensure errors are caught and processed.
Building PowerShell Functions (Publish date 9/14)
We'll take what you learned in the previous articles and use that to build our first function. We'll cover what a function is, it's purpose, why you would want to create a function and build a few. This article will be a critical one in your PowerShell scripting journey.
Provisioning an Azure Virtual Machine with PowerShell (Publish date 10/2)
In this last post, we'll bring together all of the knowledge learned in the previous posts to build a PowerShell script that serves a specific purpose. This tool will be a real script that uses all of the skills you've learned up to this point. To keep it Azure-focused, you'll learn how to build a PowerShell script that creates an Azure virtual machine from scratch.
Get ready to get your hands dirty with PowerShell!
— Adam Bertram