powershell custom properties

Post on 05-Dec-2014

1.357 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

WELCOME TO TECH | IMMERSION

Windows PowerShell and Custom Property StuffPresenter: Don Jones

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

Customize Data Outputwith Calculated Properties

o What are calculated/custom properties (“columns”)?

o Making the hashtable for a calculated property

o A bevvy of examples

What Are They?

o PowerShell has the ability to dynamically extend objects

o Adding a NoteProperty lets you attach custom information to an object

o Do this to…– Create custom displays– Align pipeline output and input for parameter

binding

Making the Hashtable

@{ name='whatever'; expression={$_.whatever}}o Name can also be Labelo Shorten with “n” (or “l”) and “e” for brevityo Each @hashtable is an element; include

multiple elements in a comma-separated list

The Trick

o Within the expression {scriptblock}, $_ is a placeholder for whatever object was piped to Select, FT, or FL

o Use $_.whatever to access properties and methods of that object

o This makes slightly more sense in an example. Coming right up.

Use With What?

o Use with…– Select-Object (Select)– Format-List (FL)– Format-Table (FT)

Examples, Examples, Examplii

o Calculating free disk percentage

o Performing a second WMI query

o Changing “name” to “computername” for parameter binding

o Fixing columns in a CSV for AD user creation

ADVANCED TIME!

o Hashtable also accepts…– FormatString– Width– Alignment (Left, Center, Right)

o FormatString is useful anywhere; the other two only with Format-Table

More Examplii

o Making disk space look prettier (commas!)

o Aligning and controlling column width more precisely

o FormatString uses same stuff as –f operator

Thank you.

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

top related