Windows PowerShell can be a little intimidating to learn at first. I think the most essential thing is to learn the very basics of how it functions and a little bit of why as well. I remember first using PowerShell, I had to know this exact command and run it this precise way otherwise this big ugly error would come up and yell at me.
It is true you must know the Commandlet and its associated parameters. But there are ways to get help and discover what commandlets are out there, as well as making shortcuts and even creating your own commandlets. I will start with the very basics and then expand upon that in further posts.
So first things first, let's fire up PowerShell.
In Windows 7 go to start, run, and type in PowerShell. Right click and click Run as Administrator.
If you plan on using PowerShell a lot, you may find it useful to right click and go to Pin to Taskbar.
Basic Commandlet Usage
So let's jump right into a simple commandlet, Get-ChildItem.
By default this Commandlet will list the contents of the directory you are in. This commandlet also has aliases. You can type "ls" or "dir" and get the same results.
PowerShell mounts a few "drives" by default that the contents of which can be listed with Get-ChildItem. To see these drives type Get-PSDrive.
One of the drives will list your environment variables. To list them, type Get-ChildItem env:
To get a specific item fron the env: drive type: get-childitem env:username.
If you want just the value of username, type: (get-childitem env:username).Value
So now that we've used a couple commandlets, let's learn about piping.
Piping
In PowerShell you can pipe commands using "|". By doing this you're passing the objects from left to right. Let's format the output from "Get-ChildItem env:".
Type Get-ChildItem env: | Format-Table -a
The output is formatted nearly the same, but now the columns are autosized. You can also pipe commandlets to Get-Member:
(Get-ChildItem env:username) | Get-Member
Get member will list the methods (actions) or properties (values, essentially) available for an object. We used .Value earlier to get just the value for the username environment variable.
More to come!
No comments yet. Be the first!