How to Start Using PowerShell: A Guide
"Yeah, I know a little PowerShell." – Any random systems administrator
Not many statements can be equally as much of an understatement as an overstatement. Some who say this are being quite humble, though they probably do know quite a bit about PowerShell. Others tend to think knowing about PowerShell qualifies as knowing how to use it.
For those that 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 PowerShell 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.
Know Nothing About PowerShell? That's Okay.
First things first. If you don't know PowerShell, that's perfectly okay. It's all good if you know of PowerShell. If you have never actually used the tool, it's OK to come clean. Nodding in agreement in peer discussions and throwing PowerShell into your CV to hopefully get an edge can actually be a reality much quicker than you think.
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 very basic focus at that. The other aspects come together a little more clearly when you get more experience in the shell portion of PowerShell.
PowerShell was developed by Microsoft and is continually being designed and developed to interact with Windows desktop operating systems, Windows Server operating systems, Office 365 resources, and Azure cloud resources. Needless to say, it will be an integral part of almost all of the universe of Microsoft products. It is designed to allow engineers and support personnel to manage their respective responsibilities in more efficient ways by allowing bulk creation and modification of resources such as files, folders, settings, and configurations.
It is most known for its unique and very user-friendly verb-noun nomenclature of cmdlets, pronounced as 'command-lets'. Cmdlets are the actual commands that are 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. In fact, many of the commands that you would normally run inside a command prompt actually can be run inside a PowerShell console. If anything, give it a shot the next time you go to 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 that 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 completely 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 360 users to be added 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 types of 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 will be needed more often in your daily support toolbox. It's fairly 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 Your 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. Admittedly, Microsoft is making it pretty easy to get to things even within the GUI, but this is a good example of a resource most, if not all, IT support people will be very familiar with. If you open a PowerShell console, to get a list of the installed services, just simply input Get-Service and press enter. You will get a quick blast of all the services that are installed on the local system as well as their current status of Running or Stopped. This would be very handy to see if a certain 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 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:
Start-Service -ServiceName spooler
Stop-Service -ServiceName spooler
Luckily PowerShell is very wildcard friendly when it comes to 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 will list all the services which start with the word remote. This will 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 as well.
Taking this just one step further to really get a return on this tiny bit of knowledge of services, let's check services on a remote machine. Assumptions will be made here that you are in a Windows-domain environment and you have some level of administrative access to the remote machines you manage. You can use the same exact cmdlets discussed previously, but you just need to add one parameter and value. To check the print spooler service on remote server named PrintServer01:
Get-Service -ComputerName PrintServer01
This will list all the services that are installed on the remote machine, just like it would the local system we did earlier. This capability in and of itself pays off very quickly. This will save you from either using RDP to log into the remote server to check the service, or from adding the remote server into a local MMC snap-in. There are also ways to stop/start/restart services on remote servers as well, using what is called the 'pipeline', but that is out of the scope of this post.
One other command that can be used right out of the box, without parameters is Get-NetIPAddress. This will give you a listing of all the network adapters on the local system as well as a good amount of information about each adapter. You really see in this output the inner workings behind the GUI. You can see so much more information about things that you normally just see as an icon within the GUI. The beauty of seeing more information, is that you can always use PowerShell to manipulate and search on any and all of that extra information. For instance, if you wanted to make changes to only specific network adapters, you can search or filter for only the ones that have a certain value. The possibilities are really endless!
How to Further Your PowerShell Learning
Now that you have been given the absolutely slimmest of slices of PowerShell, it's up to you to continue the quest up that mountain. 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 very powerful library for every single cmdlet that exists and has plenty of examples of how to use them. PowerShell itself provides a good resource for explanations and examples. Get-Help Get-Service will give you more information on our above example.
The PowerShell community is also a very open and helpful place to learn as well. The subreddit r/PowerShell as well as the site PowerShell.org have a very thriving community of people with varying degrees of experience. You can always get some guidance in 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 just find yourself frantic to schedule and automate a good amount of your workload so that you can give yourself time to learnmore about PowerShell.
delivered to your inbox.
By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.