One Problem, Many Solutions
In PowerShell and pretty much any aspect of configuration management, there can be many ways to solve a problem. This really will come down to style at the end of the day. There is a camp where being super explicit in your script/language/examples etc. is desirable. There is another camp that takes the twitter approach and it is a bit of a challenge to see how much functionality can be crammed into the least number of characters as possible. And of course, there are the majority of folks who land smack in the middle.
Which one are you? For many people out there PowerShell is still relatively new and in my opinion being as explicit as possible is a huge benefit to the learning process. Typing everything out can be a pain but with the ISE especially there is amazing auto-complete and IntelliSense which makes this process very easy. Also, in the long run what you write today may not be looked at for a while or some colleague in the future may need to look at what you wrote. Being explicit in your scripts will benefit both of these scenarios.
On the other hand learning the short-cuts can be super valuable and will help you become a true master of the language. If you use a lot of short cuts make sure to comment your scripts to show what it is you are doing. I know how much IT folks, especially scripters love to comment!
So, these three lines deliver the same information...
- PS C:\ > Get-ADUser -Identity Kevin | Select-Object -ExpandProperty PropertyNames
- PS C:\ > Get-ADUser Kevin | % PropertyNames
- PS C:\ > (Get-ADUser Kevin).PropertyNames
And there are more ways to get the same results... Check out this quick walk through...
Kevin
No comments:
Post a Comment