Your First 30 Minutes in PowerShell
So you’ve finally gotten the memo and decided it was time to start learning PowerShell. Excellent. But before you go off searching YouTube for free training videos or simply start floundering around at a PowerShell prompt, which will frustrate you to no end, take a moment to lay out the groundwork.
- Related: Why Learn PowerShell?
Although PowerShell isn’t something that you can master in 24 hours, you can learn enough in a short period of time to accomplish some simple and basic tasks. This article is aimed at the absolute PowerShell beginner running at least PowerShell 3.0 on a Windows 7 desktop. For beginners, the fundamentals of PowerShell don’t change between versions 3, 4, or 5.
Launching an Elevated Session
To start, I recommend launching PowerShell in an elevated session. Even if your account has admin rights, some of the things you will need to do will require an elevated session. Find the PowerShell console icon on your Start Menu, right-click and choose the ‘Run as Administrator’ option. PowerShell should now open in the traditional blue screen.
What is “Inside Microsoft Teams”?
“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.
You might even see the window titled with Administrator. You can use the same commands you know from the legacy CMD.EXE window to navigate around. You can use commands like dir and cd. The output might look slightly different, but it should still recognizable.
Note: Be aware that when you type dir you aren’t really typing the DIR command, so if you see errors hold on a few minutes.
Find Your Version
The next thing you might want to do is to identify what version of PowerShell you are running. At a prompt, type $psversiontable, and press Enter. What you just typed is a built-in variable that shows you version information about the different components of the Windows Management Framework. PowerShell is actually just one piece.
In this screenshot, taken from a different computer, you can see the PSVersion value is 5.0.10586.51, or v5. That’s generally the most important piece of information to know. Eventually you will start running scripts and PowerShell tools that might require a minimal version. If you get an error saying the script won’t run, you can always check your version information.
The first major step you need to take in the first 30 minutes is to update PowerShell’s help files. This requires Internet access. Out of the box, PowerShell ships with minimal help documentation. All you need to do is type the command Update-Help and press Enter. The command will search your computer for all PowerShell commands and check them for online links for downloadable help.
You only need to do this once a week or so, if that. By default Update-Help will only connect online every 24 hours, so if you need to rerun the command, use the –Force parameter.
Read About Topics
The next step is to begin familiarizing yourself with all of the great help documentation you just downloaded. Start out by running this command:
I used a wildcard because you might see different topics depending on your version. You will probably get a list of matching items.
All of these about topics are concept-oriented documentation. Once you see the full name, ask PowerShell help to display it.
If you see “More” at the bottom of the screen, press Enter to advance to the next line, press the space bar to advance to the next “page”, or press Q to quit.
I encourage you to take the time to really read the document, don’t merely skim it. If some of it goes over your head, don’t worry too much about that now. Take the next several minutes and run these commands, reading each help topic.
- Help about_objects
- Help about_pipelines
- Help about_command_syntax
- Help about_parameters
PowerShell also has help for all the commands you will be using. Remember when I said typing dir isn’t the same as the DIR command you may be used to? Ask PowerShell for help:
You should see something like this.
Technically, the dir command is an alias for a command called Get-ChildItem. As alias is merely an alternate name, which may be easier to type or serve as a transition aid as is the case here. Thus if you wanted to list all subfolders, you would use the –Recurse parameter.
dir c:\windows\softwaredistribution –recurse
By default PowerShell displays a short version of help. You can read full command documentation with the –Full parameter.
Help dir –full
Many commands also have a link to an online version of help, which is sometimes more up-to-date than what you can download. To see the latest version of help, use the –Online parameter.
Help dir -online
Get in the habit of reading help all the time, even for commands you think you know. New versions of PowerShell might add a new parameter or feature, and unless you read the help, you’ll miss out.
Run Basic Commands in PowerShell
Hopefully you still have a few minutes left to dip your toe in the PowerShell waters. Try running a few basic commands:
- get-service | where status –eq ‘running’
- get-process | sort workingset -descending |select-object -first 5
Again, don’t feel you have to completely understand what these commands are doing or how they work. I want you to see how easy it is to use PowerShell. If you want to learn more about the commands read their help documentation.
PowerShell: Use It or Lose It
Learning PowerShell is no different than learning a foreign language. It will be rough at first and might feel like an epic struggle, but stick with it. Master the basics like you would any language before diving into more complex scenarios and topics.
I strongly encourage you to find ways to use PowerShell every day. Even if you do nothing other than read a new help topic. The more you use it, the more you’ll understand it, which means it will get easier, and you’ll want to use it more.
At this point, you can start searching for other educational sources, although I certainly hope you’ll stay connected with the content I write for Petri. I also maintain a page on my own blog with my suggestions for PowerShell resources.
Welcome to an exciting new world. Let’s get started.