0 0 1 380 2172 Concentrated Technology 18 5 2547 14.0 Normal 0 false false false EN-US JA X-NONE
Chapter 19 is a combination of all the killer tips this book has covered so far, placing all the knowledge learned into a reusable chunk of code, a function. In essence to share, build on, and place in your toolbox. Why would you want to share? Look, just don't be THAT admin, the script hoarder, just share man that's what our industry is about. Sharing knowledge and pushing one another to new limits. That tone of sharing knowledge fills the pages of this book.
Prior to this book I struggled with PowerShell output. I used to try to stuff so many cmdlets into a script or function that the output was just nasty and barely worth producing. This chapter walks you through focusing on a few WMI classes, some variables and output. It sounds pretty straight forward doesn't it? The logic is there but the output just doesn't add up at first. The building of the parameterized function starts with outputting the data using Write-Host at first, then switching to Write-Output. Lining up the data just does not happen when you are pulling text within PowerShell, at least not easily.
While I was reading I was thinking that PowerShell is object based, why are we pulling text? Does points out that when using PowerShell we need to stop fighting the shell and instead work with it. Change our focus from struggling with text and move into working with objects. Working through all the sections of the chapter I did get a bit frustrated when the output was not what was required. The payoff comes with learning about PSObject.
PSObject I wish you were in section 19.2. Using PSObject allows for really clean looking functions. You seriously have to try this; it will really change your habits on producing code that works. This is where it really comes together. The two keys to success that are mentioned within this chapter are Breaking Tasks Down and Output Objects. Changing ones mentality from quick batch scripting to objects is a bit challenging, until you see the elegance and clarity of the output.
Export-CSV is something I have been using since page 39 and it really struck a chord with how I can get data to those who need it, it's great when folks need system info for inventories or billing and you can shoot them what they need in a format that they can input into a database table.
Looking forward to building on this chapter with logic and loops!
This Month of Lunches snack was served up hot and seconds are available at the following: http://morelunches.com/
Mar 28 2012, 04:37 PM