12
WELCOME TO TECH | IMMERSIO Windows PowerShell and Custom Pro Presenter: Don Jones

PowerShell custom properties

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: PowerShell custom properties

WELCOME TO TECH | IMMERSION

Windows PowerShell and Custom Property StuffPresenter: Don Jones

Page 2: PowerShell custom properties

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

Page 3: PowerShell custom properties

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

Page 4: PowerShell custom properties

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

Page 5: PowerShell custom properties

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

Page 6: PowerShell custom properties

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.

Page 7: PowerShell custom properties

Use With What?

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

Page 8: PowerShell custom properties

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

Page 9: PowerShell custom properties

ADVANCED TIME!

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

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

Page 10: PowerShell custom properties

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

Page 11: PowerShell custom properties

Thank you.

Page 12: PowerShell custom properties

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