How Do I Learn PowerShell? (For Beginners)
I work with a lot of different technologies every day, some are fun to use while others are a little boring and repetitive. To help with the repetitive part, I turned to scripting. (Blogging has been pretty fun too!)
Recently I started thinking about how much I have learned about scripting over the past few years, and then I thought about sharing this information with my readers. So I came up with this article in the form of a question: How do I learn Powershell for Beginners?
The answer is with 5 steps to get you started on how to learn Powershell for beginners! As a programming beginner myself I really enjoy creating scripts in Powershell, and in the relatively short amount of time that I have been learning Powershell I have made some good progress.
Table of Contents
- Step 1: Find a goal
- Step 2: Research
- Step 3: Practice Practice Practice
- Step 4: Share your ideas with others
- Step 5: Repeat Steps 1 to 4
- Wrapping Up
I have learned how to at least get started with learning Powershell and I think that you will find these tips very helpful. I am by no means an expert, but I have found some useful hints and tips along the way on my journey to learning Powershell.
It’s no secret that Powershell is my go to tool when it comes to automation and Windows management. (Even though I am learning Python and Blazor WebAssembly right now) For beginners it feels like an insurmountable obstacle that is too difficult to attempt. Luckily, I managed to figure out how to teach myself some techniques to just get started.
I wont be teaching too much about Powershell basics in this article, but we can look at a few simple techniques that will help you to learn Powershell. Wait, wait, wait I hear you say. “Learn Powershell without actually teaching any specific Powershell skills?!” Sounds weird right?
This techniques applies to anything, not just this fabulous programming language. (And yes, it is a programming language. We actually fleshed out this idea process in our popular “Is Powershell considered a programming language?” article, so give that a read when you’re done here!”
Step 1: Find a goal
You might be wondering what I mean by this: the goal is to learn Powershell, right? This is not wrong, but you can reconfigure this in your mind to help you side step the difficulty of the task of learning any new skill. This principle tells us to learn a new skill by pursuing a goal.
Think about what cool kinds of applications you want to build with Powershell, or think of a task that you have to do hundreds of times a day that could do with automating. Once you have set a goal of what you want to build in Powershell, then you can start to learn Powershell as a side effect of building a useful tool.
Here is a quick example of what I mean. Let’s look at a real world example I created when I was working as a help desk support engineer. The company used an ancient help desk suite that could not be developed any further as the company that sold the software no longer existed.
Our management team decided that it was necessary for all tickets to have a date and time stamp on them, followed by the support engineer’s name. The application did not have this feature, so it was up to us to manually type in the date and time at the end of each update to a ticket. This was a very unproductive extra step and after about a week of having to do this manually I had had enough.
To solve my problem I turned to Powershell. Below is a very short script that I created to automate this tedious task.
All this does is grab the current date and time, adds a space then my name, then it copies it to the clipboard. Now all I do is paste into the ticket comment window and I am done. To access the script I saved it as a batch file like this:
Powershell.exe -executionpolicy bypass -File C:scriptsNoMoreTypingTheDateForMe.ps1
You can then save this as a shortcut on your desktop or in your taskbar, and when I needed to update the ticket with my data then I would simply click my script and instantly have that data sitting in my clipboard. AutoHotKey is another great way to accomplish the same thing, but I am using this as an example of learning how to start with basic Powershell scripts.
Step 2: Research
Any time that you learn a new skill to do with scripting or programming it has usually come as a result of many hours of scouring the internet for answers. Google really is your friend, but only up to a point.
Don’t let confusing posts cloud your will to learn, so if you find that you are really not understanding something then take a break and come back to it. There will be times that something just does not work, and that is ok.
It is important to remember that the longer you try different things, the more likely you will be to succeed. You will eventually run out of ways to be wrong, and the correct solution will appear, even if it isn’t the one you wanted.
I find that I learn best from trying things for myself, so it is always good to find sources where you can safely copy code from to start experimenting with. Places like StackOverFlow, SpiceWorks, and even Microsoft’s own Powershell Documentation are very helpful resources.
You will also fin amazing YouTube channels that are helpful, and Reddit has an amazing Powershell Subreddit. This is a community that is very responsive and usually helps to get scripts working in no time.
I have languished for many hours on my own while failing to get a script running, only to find the answers in the above resources, so be sure to use them on your own journey.
Step 3: Practice Practice Practice
I have a scripts folder that is bursting at the seams with so many scripts that I have written over the years. I have created multiple services and applications that do all sorts of useful things.
The most useful feature that Powershell has is its ability to communicate with SQL databases. I have been able to build really good applications that track and manage data while remaining light weight and native to Windows.
The point is that even though not all of these scripts ended up being as great as I had hoped, they still counted as practice. Here are some cool practice exercises that you can try. Think about how you can get your script to:
- Loop around so that it is always running.
- Create a condition based loop so that it stops when something changes
- Figure out how to send emails from your script
- Create a user interface
- Create a useful tool to minimize unnecessary repetition
Learning how to create a Powershell script requires you to put in the time. Anything that is worth learning is worth the time and effort.
If you are new to programming principles then you might find that there is a lot to wrap your head around, but the more you do it, the easier it gets. I think about learning Powershell like going to the gym: it seems like a chore at first, but after you’ve spent the time doing it you wonder what all the fuss was about.
Keep at it and you will see ‘gains’ in your knowledge!
Step 4: Share your ideas with others
Not many things grow well in the dark, and projects in isolation are very similar in a way. It is easy to get stuck on a bad idea or a solution that isn’t working. For this reason it is sometimes necessary to share a project or a concept, and you need to bounce ideas off of other people.
If you know other people that are knowledgeable in scripting and programming then try and ask them if they would mind having a chat with you about what you are trying to do. If you don’t know anyone, then you can reach out online and find other people that are trying similar things to you.
Some of the resources that I listed earlier are a great place to find help for problems, and an ear to listen to what you are trying to do.
Step 5: Repeat Steps 1 to 4
This really is a repetition game, which is why the gym analogy I used earlier is so fitting. You need to practice everyday and keep your passion alive for creating scripts and programs. Try to use this exercise regiment as a way figure out how you can speed things up and make your life at work all the more efficient. Once you have conquered each foothill project you can set your sights on even greater peaks, and start to learn more about how to create those applications.
You will come to a point where you reach the limits of what you are trying to create with Powershell, or you might find that there is an entirely new and exciting programming language that you would like to transition into. Powershell is a great way to learn about concepts like variables and scopes, and how the different objects are used in a pipeline. With all the resources that are available to us all on the interenet it is a totally acheivable goal to set for yourself.
What is PowerShell?
PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language.
Why should I use PowerShell?
PowerShell is a great way to get into scripting and programming in general. Learning PowerShell can be a great way to learn automation and hence, programming in other languages too.
How to get started with PowerShell?
This might sound a little obvious but the best way to get started with PowerShell is to start. Figure out a basic task that you want to accomplish and then research how PowerShell can help you. There are tons of resources out there to help you with this.
What is the basic format of all PowerShell commands?
Each command has its own syntax and parameters . A command will indicate what parameter it expects to be passed and in what form (string, integer, array). It’s important to know this before you pass a variable that may not fit the criteria.
How do I get a list of PowerShell commands?
The most commonly used cmdlet for accessing a list of PowerShell commands is the Get-Command cmdlet.