An Introduction to Microsoft PowerShell - Harnessing the Power
(Page 4 of 4 )
You can customize output further by sorting from the output as well. Let’s use the Get-Process cmdlet as an example. It lists all of the currently running processes. You can sort results using the Where-Object method in many different ways. In this example, I’m going to use the command:
Get-Process | Where-Object { $_.ProcessName –match "^e.*" }
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
461 14 42848 53732 124 24.13 2792 explorer
The use of regular expressions is far beyond the scope of this article but essentially this searches for and returns only processes beginning with the letter E.
We’re only beginning to tap into the true power that PowerShell has to offer. Not only do you have a full range of cmdlets available to you, but you can also add third-party ones and even write your own. It truly is the most flexible command line environment.
Another very cool feature that I like in PowerShell is its ability to work directly with the Windows registry. Try typing Set-Location HKLM:. You’ll notice by the change in prompt that your are sitting at the root of the HKEY_LOCAL_MACHINE registry hive. From here you can navigate and view the registry as if it were a standard directory structure.
You can use the Get-ChildItem cmdlet to get a “directory” listing for each level of sub keys. To see a listing of keys at the current location you’ll need to use the Get-ItemProperty cmdlet instead.
As you can see, PowerShell has a lot of power built into it. It’s the most advanced command line environment to date. As you experiment and learn more you’ll begin finding even more robust ways of getting things done.
In the future, I will be presenting a series of articles to help you learn how to use this new environment as well as how to write PowerShell scripts. Download the latest copy of PowerShell and start exploring. Until next time.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |