Download - PowerShell custom properties
![Page 1: PowerShell custom properties](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/1.jpg)
WELCOME TO TECH | IMMERSION
Windows PowerShell and Custom Property StuffPresenter: Don Jones
![Page 2: PowerShell custom properties](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/2.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/3.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/4.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/5.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/6.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/7.jpg)
Use With What?
o Use with…– Select-Object (Select)– Format-List (FL)– Format-Table (FT)
![Page 8: PowerShell custom properties](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/8.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/9.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/10.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/11.jpg)
Thank you.
![Page 12: PowerShell custom properties](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b29db4af9f602c8b4570/html5/thumbnails/12.jpg)
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