Tuesday, October 25, 2016

Don Jones Month of Lunches Day 7

The original link can be found at: http://powershell.com/cs/blogs/donjones/archive/2012/03/05/will-day-7.aspx
Chapter 7 gets into the pipeline deeper to clear up a lot of things.  I still have a hard time with some of the concepts I have avoided day to day.  Pipelines took me a while to grasp, and, I certainly dont understand them completely yet.  As an aside, I think of commands (and scripts) as small machines to automate tasks.  This helps me visualize the concept a little better.  The old crank engines on Ford Model Ts specifically come to mind. With each crank the cylinders go down and up.  Using this mental model I see the operating system cranking on one thing-the pipeline object-at a time in sequential fashion.  That, to me, is one of the clearest ways to explain the pipeline.  I dont know if this will help anyone else, but, it just gave me a real tangible image to work with.

I still struggle with are ByValue (Section 7.2) and ByPropertyName (Section 7.3).  Although I worked through the examples in the book it does not fully make sense.   Don gave a great explanation, but, I suspect this will be something I need to use a bit until it clicks.   Normally my brain just "gets" things.  When it does not, I have to work pretty hard to figure them out.  Then, all of the sudden, I get it.  One of the fun parts of being an intuitive person in a logical trade.  To distract myself I tried to come up with a function to list all of the Cmdlets and specific parameters that take pipeline values ByValue and ByPropertyName, however, that proved to be unproductive.  Perhaps later it too will come to me.  So, back to work.

Finding a weak spot does not make me terribly happy.  However, part of the reason I felt doing the Month of Lunches was to do a full review of PowerShell fundamentals so I could uncover holes. While not getting this distinction certainly is not a show stopper it show see what I need to work on so I can go back and focus on the gaps in my knowledge base with a little TLC.  I did like the section on using parentheses.  A simple technique used by a lot of more experienced PowerShell I follw use is to wrap something in parentheses as an argument.  For a while, I had been using the cmdlet-pipe-foreach pattern.  That is the long way around the block.  Just use the parentheses; by order of precedence these are interpreted first.  Once the output of these cmdlets returns it gets passed to the parameter as arguments.  Less work, more results.

I enjoyed the sections on creating new AD users.  It took me a little while to get what the difference being highlighted in Sections 7.5 and 7.6.  A while back I learned about using expressions with Select and found that to be just plain awesome.  At first I thought the issue was that there were some pieces of data in the wrong columns.  I kept studying the two lists wondering what I was missing.  Then, as I worked through the second example I finally spotted the difference being with the csv headers, not, with the data.  All of the sudden I was not preoccupied with some magic I was not seeing, and, simply shook it off as something obvious I was not paying attention to.

I still have not found a clear approach on how to use parentheses to retrieve arguments to pass to  parameters.  Looking back over what was covered in Sections 7.2-7.4 I suspect the answer rests in understanding ByValue and ByPropertyName.  I hesitate to use this obscure example, but, it encapsulates something I learned in this chapter.   I want to use Trace-Command (a really deep dive cmdlet), but, I hate using TraceSources with Console in the Name.  The console goes nuts.  I tried to find a workaround to exclude specific TraceSources.  I was only able to do this after I examined the output of my command.  I was trying to pass PSTraceSource objects to the -Name parameter when it really wanted strings.  By looking more closely at the help (to see the expected type) and using Get-Member (to identify what was sent) it became clear, and, so did my solution.

Yeah, Will, I gotta admit I still struggle to teach pipeline binding, too. In the 2nd edition of the book (for v3) Ill probably try a different approach yet again. Its just a touch concept. But parentheses dont depend at all on ByValue or ByPropertyName. Consider Get-WmiObject -class Win32_BIOS -computername (xxx). The "xxx" can be replaced by any expression that produces a collection of String objects (since youve got some programming experience, Im comfortable using that terminology). E.g., (a) Get-Content names.txt (b) Get-ADComputer -filter * | Select -expand Name, etc. So long as the parenthetical expression produces a collection of objects, and those objects are acceptable to the parameter (-computerName accepts a String), then itll work. Hope that helps...

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger