With every new version of Windows there appears to be a new interpretation of the Windows shell. First there was MS-DOS, for a while it’s been CMD, and now it’s PowerShell.
However, Microsoft seems to have made a major breakthrough with PowerShell. It is not just another scripting language instead it works with .NET objects. And it does this by using Cmdlets.
What is a Windows PowerShell Cmdlet?
A Windows PowerShell Cmdlet (or Command-let) is the means by which .NET objects can be accessed from the command line. A Cmdlet can easily be recognized from the fact that its name will consist of two elements: a verb and a noun. For example, one of the most useful Cmdlets is:
However, there are abbreviations for some of the Cmdlets, for example:
Can also be typed as:
Which is command familiar to many Linux users as the command to view details about currentlyrunning processes. Interestingly there are a number of other Linux-PowerShell parallels, for instance:
- “man” is the same as “Get-Help –detailed”
- “ls” is the same as “Get-ChildItem”
- “pwd” is the same as “Get-Location”
Of course, there is a small issue here (as some readers will have already discovered): PowerShell is not installed by default.
Obtaining PowerShell
PowerShell is installed in Windows Server 2008 and is also part of Windows 7, but it does not come ready loaded with XP or Vista. Users of these platforms will need to download the PowerShell installation program from Microsoft’s How to Download Windows PowerShell 1.0 web page.
Running PowerShell
Once PowerShell has been installed then it can be run in two ways:
- Click on “Start”, “Run” and then type in “powershell”
- Start a new command prompt and then type in “powershell”
At which point the user can start using the PowerShell commands.
A Simple PowerShell Example
One very useful Cmdlet is ps (or get-process). This lists the currently running processes and details such as the number of pages of memory used by each process and the percentage of processor usage. The result will be something like:
The list is sorted alphabetically according to the process name. However, it may be more useful to sort by the WS field so that the processes using the most memory appear at the top of the list. To do this the user “pipes” the output of ps to a second Cmdlet “sort-object”:
Now the result will be something like:
If the output is examined then “powershell” can be seen as one of the processes. Obviously the user will not want to see that, and so a filter can be added. It’s also worth noting that the piped Cmdlets can be split over multiple lines:
Finally the concatenation symbol (>) will send the result output file after the information has been converted to HTML so that it can then be viewed in a web browser:
The result will be an HTML file containing only the alphabetically sorted, currently running processes and the amount of memory that they’re using.