Putting them together
The several *-Object
cmdlets that we've discussed in this chapter will be the foundation to your experience with PowerShell. Although, we only used them with Dir
, Get-Service
, and Get-Process
, this is only because I can be sure that you can use these cmdlets on any system. The way that you use the *-Object
cmdlets is the same whether you're dealing with files and folders, virtual machines, or mailboxes in Exchange. Since PowerShell gives you objects in all of these situations, these cmdlets will enable you to manipulate them using the same techniques.
Here are a couple of concrete examples of how the methods of using these cmdlets are portable between the types of objects. First, to get the largest five files in the c:\Windows
folder, you would do this:
Dir c:\Windows | Sort-Object –Property Length –Descending | Select-Object –First 5
Similarly, getting the five processes that are using the most file handles would look like this:
Get-Process...