{"id":72511,"date":"2015-10-26T00:01:00","date_gmt":"2015-10-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/10\/26\/spelunking-with-show-object\/"},"modified":"2019-02-18T09:34:46","modified_gmt":"2019-02-18T16:34:46","slug":"spelunking-with-show-object","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/spelunking-with-show-object\/","title":{"rendered":"Spelunking with Show-Object"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Guest blogger, Tim Warner, talks about using the <\/span><b style=\"font-size:12px\">Show-Object <\/b><span style=\"font-size:12px\">cmdlet.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I have another guest post by <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/tag\/timothy-warner\/\" target=\"_blank\">Tim Warner<\/a>. By the way, you can meet Tim and other PowerShell enthusiasts at the Nashville PowerShell user group meeting on Wednesday, October 28. I will be there making the presentation. The Scripting Wife will also be in attendance. Also in Nashville this week is <a href=\"http:\/\/www.killernashville.com\/\" target=\"_blank\">Killer Nashville<\/a>. I will be speaking at that conference too, but not about PowerShell. Hope to see you in Nashville. Take it away Tim&#8230;<\/p>\n<p><strong>Spelunk<\/strong>&nbsp;<span style=\"font-size:12px\">[spi-<\/span><b style=\"font-size:12px\">luhngk<\/b><span style=\"font-size:12px\">], <\/span><i style=\"font-size:12px\">verb<\/i><span style=\"font-size:12px\">. To explore caves, especially as a hobby.<\/span><\/p>\n<p class=\"FT\">When I heard <a href=\"http:\/\/www.jsnover.com\/index.html#Oct11_jps_1\" target=\"_blank\">Jeffrey Snover<\/a> use the word &quot;spelunk&quot; to describe PowerShell command and object discovery at <a href=\"https:\/\/channel9.msdn.com\/Events\/Ignite\/2015\/BRK4451\" target=\"_blank\">Ignite 2015<\/a>, I just knew I had to use it in a tutorial! Today I&#039;m going to teach you how to use the wonderful <a href=\"http:\/\/www.powershellcookbook.com\/recipe\/bpqU\/program-interactively-view-and-explore-objects\" target=\"_blank\">Show<b>&#8211;<\/b>Object<\/a> function from PowerShell team member, <a href=\"http:\/\/www.leeholmes.com\/blog\/\" target=\"_blank\">Lee Holmes<\/a>, to gain insight into PowerShell pipeline objects.<\/p>\n<h2>Typical method for PowerShell object research<\/h2>\n<p class=\"FT\">We must first recall that PowerShell pipelines are very different from, say, Linux pipelines. Rather than consisting of text, PowerShell <i>objects<\/i> are &quot;three-dimensional&quot; data structures that consist of properties (descriptive attributes), methods (actions the object can undertake), and events (actions that can be undertaken on the object). Collectively, these data elements are called <i>object<\/i> <i>members<\/i>.<\/p>\n<p class=\"FT\">For instance, take <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/hh849804.aspx\" target=\"_blank\">Get-Service<\/a>. Unless you perform filtering, you receive an object collection as output. You probably know that <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/hh849928.aspx\" target=\"_blank\">Get-Member<\/a> shows us the object&#039;s .NET Framework type name and its properties, methods, and events. Here&#039;s partial output from my Windows 8.1 administrative workstation running <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2015\/08\/31\/windows-management-framework-5-0-production-preview-is-now-available.aspx\" target=\"_blank\">Windows Management Framework 5.0 Production Preview<\/a>:<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">PS C:\\&gt; Get-Service | Get-Member<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">&nbsp;&nbsp; TypeName: System.ServiceProcess.ServiceController<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MemberType&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;Definition<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&#8212;&#8212;&#8212;-<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AliasProperty &nbsp;&nbsp;Name = ServiceName<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">RequiredServices&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AliasProperty &nbsp;&nbsp;RequiredServices&#8230;<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Disposed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Event&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;System.EventHandler&#8230;<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Close&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;void Close()<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Continue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;void Continue()<\/p>\n<p class=\"FT\">PowerShell objects are instances of underlying .NET classes, and by default those classes are self-discovering through a process known as <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/f7ykdhsy(v=vs.110).aspx\" target=\"_blank\">reflection<\/a>. If you want to see everything about the previous <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.serviceprocess.servicecontroller(v=vs.110).aspx\" target=\"_blank\">ServiceController<\/a> objects, pipe the <b>Get-Member<\/b> output to <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/hh849957.aspx\" target=\"_blank\">Format-List<\/a> like so:<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Get-Service | Get-Member | Format-List *<\/p>\n<p class=\"FT\">What I&#039;ve told you means that, practically speaking, we do an awful lot of get-membering and format-listing when we need to look up specific property, method, or event values. Is there (banish the thought!) an easier-on-the-eyes graphical solution?<\/p>\n<h2>Installing the PowerShell Cookbook module<\/h2>\n<p class=\"FT\">Lee Holmes (from the Windows PowerShell development team) wrote a book for O&#039;Reilly called <a href=\"http:\/\/www.amazon.com\/gp\/product\/1449320686\/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1449320686&amp;linkCode=as2&amp;tag=cookbook_recipe-20\" target=\"_blank\">Windows PowerShell Cookbook<\/a>. One of Lee&#039;s &quot;recipes&quot; describes the <b>Show-Object<\/b> function.<\/p>\n<p class=\"FT\">You can obtain the function from the book&#039;s website (see <a href=\"http:\/\/www.powershellcookbook.com\/recipe\/bpqU\/program-interactively-view-and-explore-objects\" target=\"_blank\">Program: Interactively View and Explore Objects<\/a>) if you want, but because I run Windows PowerShell&nbsp;5.0, I&#039;ll download the script by using some of the nifty PowerShellGet commands (see <a href=\"http:\/\/blogs.msdn.com\/b\/mvpawardprogram\/archive\/2014\/10\/06\/package-management-for-powershell-modules-with-powershellget.aspx\" target=\"_blank\">Package Management for PowerShell Modules with PowerShellGet<\/a>).<\/p>\n<p class=\"FT\">First we can locate the appropriate module:<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Find-Module -Name *cookbook*<\/p>\n<p class=\"FT\">Cool. So Lee&#039;s module is named PowerShellCookbook, and it is stored on the <a href=\"https:\/\/www.powershellgallery.com\/packages\/PowerShellCookbook\/\" target=\"_blank\">PowerShell Gallery<\/a> repository. Let&#039;s install it!<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Install-Module -Name PowerShellCookbook -Force<\/p>\n<p class=\"FT\">As it happens, <b>Show-Object<\/b> is only one function among many that are contained in the PowerShellCookbook module. Run the following command to see them all:<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Get-Command -Module PowerShellCookbook<\/p>\n<h2>Using the Show-Object Function<\/h2>\n<p class=\"FT\">To use <b>Show-Object<\/b>, simply pipe your desired PowerShell object into the function like so:<\/p>\n<p class=\"CodeSample\" style=\"margin-left:30px\">Get-Service -Name Spooler | Show-Object<\/p>\n<p>Take a look at the following <b>Show-Object<\/b> output, and I&#039;ll walk you through it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-26-15-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-26-15-1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p class=\"FT\">The bottom pane (sadly unresizable) shows your ordinary <b>Get-Member<\/b> output. The upper pane allows you to quickly parse the object properties. For instance, we can expand each RequiredServices node to learn that the Print Spooler service in Windows 8.1 depends on a Remote Procedure Call (RPC) and HTTP services.<\/p>\n<p class=\"FT\">If you&#039;re of the mind to do so, you can inspect the <b>Show-Object<\/b> source code by visiting the book&#039;s website (see <a href=\"http:\/\/www.powershellcookbook.com\/recipe\/bpqU\/program-interactively-view-and-explore-objects\">Program: Interactively View and Explore Objects<\/a>) or by using PowerShell directly in your console:<\/p>\n<p class=\"FT\" style=\"margin-left:30px\">(Get-Command -name Show-Object).Definition | Out-File &#039;C:\\show-object-source.txt&#039; | Notepad &#039;C:\\show-object-source.txt&#039;<\/p>\n<h2>Going further<\/h2>\n<p class=\"FT\">One of the many things I love about the Windows PowerShell community is how friendly and helpful most people are. I don&#039;t want to draw comparisons to, say, the *NIX open-source community, but&#8230;well, let&#039;s just leave that alone.<\/p>\n<p class=\"FT\"><a href=\"https:\/\/jrich523.wordpress.com\/\">Justin Rich<\/a> posted an &quot;advanced&quot; version of Lee&#039;s <b>Show-Object<\/b> function to PoshCode that you may want to look at (see <a href=\"http:\/\/poshcode.org\/5854\">Advanced Show-Object 1.0 by Jrich523<\/a>). Let me save you some work and show you the cool tree list view output from our earlier run of <b>Get-Service<\/b>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-26-15-2.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-26-15-2.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p class=\"FT\">That&#039;s all there is to it! I hope that you found this article helpful, and I thank you for reading. Take care!<\/p>\n<p class=\"FT\">~Tim<\/p>\n<p>Thanks, Tim, for sharing your time and knowledge. Join me tomorrow when I will talk about cool Windows PowerShell stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto: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.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Guest blogger, Tim Warner, talks about using the Show-Object cmdlet. Microsoft Scripting Guy, Ed Wilson, is here. Today I have another guest post by Tim Warner. By the way, you can meet Tim and other PowerShell enthusiasts at the Nashville PowerShell user group meeting on Wednesday, October 28. I will be there making the [&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":[51,56,3,570,45],"class_list":["post-72511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-guest-blogger","tag-scripting-guy","tag-timothy-warner","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger, Tim Warner, talks about using the Show-Object cmdlet. Microsoft Scripting Guy, Ed Wilson, is here. Today I have another guest post by Tim Warner. By the way, you can meet Tim and other PowerShell enthusiasts at the Nashville PowerShell user group meeting on Wednesday, October 28. I will be there making the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72511","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=72511"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72511\/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=72511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=72511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=72511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}