“Yeah, I know a little PowerShell,” may be one of the most used statements at tech conferences over the years. Not many statements can be made that can equally be as much of an understatement as it is an overstatement.
Some who say this are pretty humble, though they probably know quite a bit about PowerShell. Others tend to think knowing about PowerShell qualifies as knowing how to use it. For those who don’t know how to use it, which is still a large portion of the systems support and engineering crowd, it can be quite a daunting thought to think about where to even start with utilizing PowerShell. You’ve heard countless technical speeches, read pages of articles, and have had plenty of conversations with peers about all that it can do for you. You’re looking up at this growing mountain, and all you can do is focus on the peak, and the obvious escapes you when it comes to planning how to get to that peak. That first step is directly in front of you, at the bottom of the mountain. Let’s take that first step together.
You May Know Nothing of PowerShell, and That’s OK
Let’s get this out of the way. If you don’t know PowerShell, that’s perfectly OK. It’s all good if you know of PowerShell, but it’s OK to come clean if you have never used it. Nodding in agreement in peer discussions and throwing PowerShell into your CV to hopefully get an edge can be a reality much quicker than you think. Everyone has their own PowerShell story, and yours will be as unique as your journey through the world of IT support and engineering. You have nowhere to go but up!
According to Microsoft Docs, “PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS.” The focus of this post will be strictly on the Shell portion of PowerShell and a fundamental focus at that. The other aspects come together with a little more clarity when you get more experience in the shell portion of PowerShell.
Microsoft developed PowerShell, and it is continually developing PowerShell to interact with Windows desktop operating systems, Windows Server operating systems, Office 365 resources, and Azure cloud resources. It will be an integral part of almost all of the universe of Microsoft products. PowerShell allows engineers and support personnel to manage their responsibilities more efficiently by enabling bulk creation and modification of resources such as files, folders, settings, and configurations. It is most known for its unique and user-friendly verb-noun nomenclature of cmdlets, pronounced as ‘command-lets’. Cmdlets are the actual commands used to do something with PowerShell. Some cmdlets can be run exactly as they are, with no defining parameters. You type them in, press enter, and BOOM! You have output given to you in the console. If you are familiar with the ever-faithful command prompt in the Windows environment, you will feel very comfortable with PowerShell. Many of the commands you would typically run inside a command prompt can also run inside a PowerShell console. If anything, give it a shot the next time you usually use the command prompt. See how it can do the same things inside of the PowerShell console.
Peeling Back the Veil of the GUI
Most people love their precious GUI. They can see everything they think they need to see, and they get that warm and fuzzy feeling when they press Apply, then OK. Some of them like to live on the edge and entirely skip pressing Apply! Eventually, as you get deeper and deeper into managing servers, desktops, or Exchange, you will find yourself clicking endlessly when there is a change to be made that requires adding 360 users to 20 different Active Directory security groups. Are your fingers up for that clicking nightmare?
It’s pretty safe to say that PowerShell helps to peel back the veil that is the precious and beloved GUI. PowerShell allows you to take that task of putting AD users into multiple groups and design a few commands to do the work in a mere fraction of the time it would take to do it all through the GUI. The beautiful thing is that Microsoft wants you to utilize PowerShell for these tasks. With the emphasis on PowerShell usage in many of the major Microsoft certification exams, it’s beginning to no longer be only for the seasoned administrators, but it’s becoming something that is needed more often in your daily support toolbox. It’s reasonably accurate to say that any action, button, setting, or configuration you see in the GUI can be manipulated and set using PowerShell, even down to the nitty-gritty of the registry.
Taking the First Steps
Let’s get you started with just a few cmdlets that you can use right now if you are reading this on a Windows PC. One thing that most sysadmins and engineers interact with is the Services console. If you open a PowerShell console, just input
Get-Service and press enter to get a list of the installed services. You will get a quick blast of all the services installed on the local system and their current status of Running or Stopped. This output would be convenient to see if a specific application service is running or not.
Maybe you don’t want the whole list of services, and you are looking for a specific service. Let’s say you want to see if the spooler service is running. You can call it out by name using the -ServiceName parameter like so:
Get-Service -ServiceName spooler
This output will give you the single listing for the Print Spooler service and its status. Let’s say the service is currently is started or stopped, and you want to either stop it or start it. You could use the following input to stop/start the spooler service:
Start-Service -ServiceName spooler Stop-Service -ServiceName spooler
By default, these lines won’t list the service status when the command is sent. You will need to run
Get-Service -ServiceName spooler to view the current status.
Luckily PowerShell is very wildcard friendly when listing objects and names. Let’s say that you need to check on a specific service, but you aren’t quite sure what the service is ‘officially’ named. You only know that the first word is remote. That’s easy:
Get-Service -ServiceName remote*
This input will list all the services starting with the remote and allow you to narrow down your search to find the specific service you are looking for and take whatever action you need to. Don’t forget that there is also a Restart-Service cmdlet.
Taking this just one step further to get a return on this tiny bit of knowledge of services, let’s check services on a remote computer. Let’s assume you are in a Windows domain environment and have administrative access to the remote computers you manage. You can use the same cmdlets discussed previously, but you need to add one parameter and value. To check the print spooler service on a remote server named PrintServer01:
Get-Service -ComputerName PrintServer01
This output will list all the services installed on the remote machine, just like the local system we did earlier. This cmdlet will save you from using RDP to log into the remote server to check the service or adding the remote server into a local MMC snap-in. This capability in and of itself pays off very quickly.
One other command that can be used right out of the box, without parameters, is Get-NetIPAddress. This cmdlet will give you a listing of all the network adapters on the local system and a good amount of information about each adapter. You see in this output the inner workings behind the GUI. You can see so much more information about things that you usually see as an icon within the GUI. The beauty of seeing more info is that you can always use PowerShell to manipulate and search on any of that extra information. For instance, if you want to make changes to specific network adapters, you can search or filter for only those with a particular value. The possibilities are endless!
Where to Learn More
Now that you have the slimmest of slices of PowerShell experience, it’s up to you to continue the quest up that mountain discussed earlier. Putting one foot in front of the other is as easy as looking through some go-to resources for PowerShell tips. A simple Google search on a cmdlet is a good start. Microsoft Docs has a mighty library for every single cmdlet with plenty of examples of using them. PowerShell itself provides a good resource for explanations and examples. The command
Get-Help Get-Service will give you more information on our above example.
One resource that many experienced PowerShell users will remember is a top-rated book by Don Jones and Jeffrey Hicks. These giants of PowerShell own the shoulders that many stand upon when it comes to conquering the mountain of PowerShell. The book is titled “Learn Windows PowerShell in a Month of Lunches.” This easy to read book walks you through the basics of getting to know PowerShell in bite-sized pieces and ends up being a resource that you will find yourself continually referring back to when you are running into a situation that you need to use PowerShell.
The PowerShell community is also a very open and helpful place to learn as well. The subreddit r/PowerShell and the site PowerShell.org have a very thriving community of people with varying degrees of experience. You can always get some guidance from these resources. You won’t be able to scale that mountain unless you take the steps, so get going and see how PowerShell can help you with your day-to-day routine and mundane tasks that you sometimes dread. You may find yourself frantic to schedule and automate a good amount of your workload so that you can give yourself time to learn more about PowerShell!