{"id":12311,"date":"2011-10-23T00:01:00","date_gmt":"2011-10-23T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/10\/23\/focus-on-the-object\/"},"modified":"2011-10-23T00:01:00","modified_gmt":"2011-10-23T00:01:00","slug":"focus-on-the-object","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/focus-on-the-object\/","title":{"rendered":"Focus on the Object"},"content":{"rendered":"<p><strong>Summary:<\/strong> In today&rsquo;s guest article, Microsoft PowerShell MVP Shane Hoey reminds us to focus on the object.\nMicrosoft Scripting Guy Ed Wilson here. Today we have a guest article by Windows PowerShell MVP Shane Hoey. Here is what Shane has to say about himself: &ldquo;My scripting experience started back when Windows&nbsp;XP was the new kid on the block, and soon found myself scripting on a daily basis with VBScript, WMI, and ADSI . Fast forward to the Scripting Games 2009, and I finally discovered Windows PowerShell, and I&rsquo;ve been hooked ever since. One of the things I like most about Windows PowerShell is its ability to easily automate, especially my daily repetitive tasks. My background is in system and network administration, but at work they just call me the PowerShell Geek these days! By the way, I also run the <a href=\"http:\/\/powershelldownunder.com\/usergroup\/brisbane\/\">PowerShell Usergroup Brisbane<\/a>.\nTake it away, Shane.\n&nbsp;\nI&rsquo;ve changed my background to HTML color #012456, I need some inspiration, and this time <a href=\"http:\/\/drscripto.tv\/\">http:\/\/drscripto.tv<\/a> is just not what I need! After all, I&rsquo;ve been asked to write a Hey, Scripting Guy! Blog post.\nMy buddy <a href=\"https:\/\/twitter.com\/chrisbrownie\">Chris Brown<\/a> who recently started a Windows PowerShell user group in Melbourne, Australia, was on Twitter as usual. In fact, he&rsquo;d give <a href=\"https:\/\/twitter.com\/energizedtech\">Sean Kearney<\/a> a run for his money when it comes to being passionate about Windows PowerShell. And so the Twitter conversation started:<\/p>\n<p style=\"padding-left: 30px\"><b>@shanehoey:<\/b> Hey @chrisbrownie, any ideas I can steal\/borrow for a Windows PowerShell blog article I need to write ? I have scripter&rsquo;s block<\/p>\n<p style=\"padding-left: 30px\"><b>@kittenstix:<\/b> @shanehoey how to clean up Active Directory accounts using PowerShell &amp; scheduled tasks<\/p>\n<p style=\"padding-left: 30px\"><b>@ChrisBrownie<\/b>: @shanehoey umm.. how about how awesome PowerShell is and why SysAdmins should learn it?<\/p>\n<p style=\"padding-left: 30px\"><b>@jamesbannan<\/b> @shanehoey how to manage Hyper-V and VMware VMs using PowerShell \ud83d\ude09<\/p>\n<p style=\"padding-left: 30px\"><b>@Brendonrd<\/b> RT @Kittenstix @shanehoey how to clean up AD accounts using powershell &amp; scheduled tasks &#8211; PS&gt;format domain$ \/q \/y =)\nI sometimes think Twitter was created for the Windows PowerShell community!\nA few more tweets arrived, and I started to think about how I started scripting back in 2009. I remember thinking, &ldquo;OK, this can&rsquo;t be too hard. It looks just like the cmd box I&rsquo;m used to. Hey, I can kind of even understand VBScript, so this is going to be a breeze.&rdquo; And I started off by typing in <b>Help<\/b>.\nI wrote my first Windows PowerShell script that night. It was my first submission for the 2009 Scripting Games <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2009\/06\/07\/hey-scripting-guy-event-1-details-beginner-and-advanced.aspx\">Event 1<\/a>. Well, I guess you could call it a script, but little did I realize the horror of <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2009\/08\/12\/hey-scripting-guy-why-was-beginner-event-3-in-the-summer-scripting-games-so-hard.aspx\">Event 3<\/a> would stick with me for a long time to come. I still remember it to this day! In hindsight, it really was not that hard. It&rsquo;s just that I did not understand the basic PowerShell principles.\nHere is the exciting thing. Those cmdlets I learned to use during the 2009 Scripting Games&mdash;<b>Get-Help<\/b>, <b>Get-Command<\/b>, and <b>Get-Member<\/b>&mdash;I still use on a daily basis.\nSo the Twitter conversation continued.<\/p>\n<p style=\"padding-left: 30px\"><b>@shanehoey:<\/b> @Kittenstix hows this for a starting point? <a href=\"http:\/\/psdu.co\/re52NX\">http:\/\/psdu.co\/re52NX<\/a> &nbsp;&amp; <a href=\"http:\/\/psdu.co\/pWm3Em\">http:\/\/psdu.co\/pWm3Em<\/a> &nbsp;<\/p>\n<p style=\"padding-left: 30px\"><b>@shanehoey:<\/b> @jamesbannan&nbsp; have you seen this ? <a href=\"http:\/\/psdu.co\/pvJABy\">http:\/\/psdu.co\/pvJABy<\/a><\/p>\n<p style=\"padding-left: 30px\"><b>@shanehoey:<\/b> @Brendonrd have you seen <a href=\"http:\/\/psdu.co\/qhobXk\">http:\/\/psdu.co\/qhobXk<\/a> Free PowerShell Training in November\n&nbsp;\n<b>SHAMELESS PLUG ALERT&nbsp; &nbsp;<\/b>Yes, that&rsquo;s right. Shane and Chris are running <a href=\"http:\/\/psdu.co\/qhobXk\">Free PowerShell Training in November<\/a>. It&rsquo;s based on the <a href=\"http:\/\/morelunches.com\/\">More Lunches series<\/a> by Don Jones, so grab the book and join us for some free training in November.<b><\/b>\nSo it seems like previous Scripting Guys articles have already covered all the blog suggestions from Twitter.<i><\/i>\nI&rsquo;m staring at some Lego on my desk wondering, what can I blog about? Then it hit me: &ldquo;Always focus on the object.&rdquo; When I&rsquo;m helping IT pros to start learning Windows PowerShell, I often talk about &ldquo;Always focusing on the object.&rdquo; I say it all the time, but what do I really mean by it ? Well, let&rsquo;s have a look:<\/p>\n<p style=\"padding-left: 30px\">Get-process | sort PM -descend | Select -first 10\nLet&rsquo;s break down to each command by running <b>Get-Member<\/b>, and take note of the object&rsquo;s type, property, and methods.<\/p>\n<p style=\"padding-left: 30px\">Get-process | get-member<\/p>\n<p style=\"padding-left: 30px\">Get-process | sort-object &ndash;property PM -descending | Get-Member<\/p>\n<p style=\"padding-left: 30px\">Get-process | sort-object &ndash;property PM -descending | Select -first 10 | Get-Member<\/p>\n<p style=\"padding-left: 30px\">\nSo the object has not changed, but remember that it can indeed change. This time, we are going to run a similar command again:<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Select-Object &ndash;property &nbsp;Name | Format-list Name\nSo once more I want you to use <b>Get-Member <\/b>and discover a bit more about the objects in the pipeline:<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Get-Member<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Select-Object &ndash;property Name&nbsp; | Get-Member<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Select-Object &ndash;property Name | Format-List Name | Get-Member\nHey. that&rsquo;s cool. By using the <b>Get-Member<\/b> cmdlet, we can quickly see how important it is to &ldquo;focus on the object&rdquo; as it traverses the pipeline. Let&rsquo;s look at this a bit closer:<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Select-Object &ndash;property Name | Get-Member<\/p>\n<p style=\"padding-left: 30px\">Get-Service | Select-Object &ndash;first 10 | Get-Member\nDid you see that? Want a hint? Have a closer look at the object&rsquo;s type, and you&rsquo;ll notice that it&rsquo;s been changed.\nSo hopefully through these simple examples, you can see the importance on &ldquo;focusing on the object,&rdquo; especially as it passes thru the pipeline. Unfortunately, we don&rsquo;t have time today to dig too deep.&nbsp;Oh, and by the way, one more thing: don&rsquo;t forget to watch out for pipeline input <b>ByValue<\/b> and <b>ByPropertyName<\/b>!\n&nbsp;\nI want to thank Shane for his article today. I especially want to thank Shane and Chris for their efforts in spreading the word about Windows PowerShell. Check out their free training series in November. It is sure to be awesome. Join me tomorrow as I begin a new week on the Hey Scripting Guy! Blog.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: In today&rsquo;s guest article, Microsoft PowerShell MVP Shane Hoey reminds us to focus on the object. Microsoft Scripting Guy Ed Wilson here. Today we have a guest article by Windows PowerShell MVP Shane Hoey. Here is what Shane has to say about himself: &ldquo;My scripting experience started back when Windows&nbsp;XP was the new kid [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,3,4,245,45,247],"class_list":["post-12311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-scripting-guy","tag-scripting-techniques","tag-shane-hoey","tag-windows-powershell","tag-writing-scripts"],"acf":[],"blog_post_summary":"<p>Summary: In today&rsquo;s guest article, Microsoft PowerShell MVP Shane Hoey reminds us to focus on the object. Microsoft Scripting Guy Ed Wilson here. Today we have a guest article by Windows PowerShell MVP Shane Hoey. Here is what Shane has to say about himself: &ldquo;My scripting experience started back when Windows&nbsp;XP was the new kid [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=12311"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12311\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=12311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=12311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=12311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}