Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

Windows PowerShell 3.0 First Steps: Part 4

$
0
0

Summary: Microsoft Scripting Guy, Ed Wilson, shares a portion from his popular Microsoft Press book Windows PowerShell 3.0 First Steps.

Microsoft Scripting Guy, Ed Wilson, is here. Today I want to share with you another portion from my new book, Windows PowerShell 3.0 First Steps, which was recently released by Microsoft Press.

To read the previous parts of this series, see:

Creating a table

When you have between two and five properties, and you are interested in viewing in columns of data, the Format-Table cmdlet is the tool to use to organize your data. The typical use of Format-Table is to permit delving into specific information in a customizable fashion. For example, the Get-Process cmdlet returns a table with eight columns that contain essential process information. The Get-Process command and the resulting output are shown in the following image:

Image of command output

Choosing specific properties in a specific order

If the eight columns of default process information meet your needs, there is no need to think about using a formatting cmdlet. However, the Process object that is returned by the Get-Process cmdlet actually contains 51 properties and seven script properties. As a result, there is much more information available than only the eight default properties. To dive into this information requires using one of the Format cmdlets. From the perspective of the Get-Process cmdlet, there are six alias properties. Alias properties are great because they can shorten the amount of typing required. The Get-Process alias properties are shown in the output that follows:

13:40 C:\> get-process | get-member -MemberType alias*

   TypeName: System.Diagnostics.Process

Name    MemberType    Definition
----    ----------    ----------
Handles AliasProperty Handles = Handlecount
Name    AliasProperty Name = ProcessName
NPM     AliasProperty NPM = NonpagedSystemMemorySize
PM      AliasProperty PM = PagedMemorySize
VM      AliasProperty VM = VirtualMemorySize
WS      AliasProperty WS = WorkingSet

To use the Format-List cmdlet, you pipe the results from one cmdlet to the Format-List cmdlet and select the property names you want to display.

Note  The order in which the properties appear is the order in which they display in the table.

The following command displays process information from every process on the local system. The specified properties use the alias properties created for the Get-Process cmdlet. The output is in the order of Name, Handles, Virtual Memory Size, and the Working Set.

Get-Process | Format-Table -Property name, handles, vm, ws

The command to produce the formatted list of process information, and the output associated with the command, are shown in the following image:

Image of command output

Note  The Get-Process cmdlet has an alias of GPS, and the Format-Table cmdlet has an alias of FT. Therefore, the command to return a table of process information can be shortened to the following:

GPS | FT name, handles, vm, ws

Join me tomorrow when I will have another excerpt from my Windows PowerShell 3.0 First Steps book.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 


Viewing all articles
Browse latest Browse all 3333

Trending Articles