{"id":4971,"date":"2012-09-15T00:01:00","date_gmt":"2012-09-15T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/09\/15\/weekend-scripter-what-does-a-powershell-module-expose\/"},"modified":"2012-09-15T00:01:00","modified_gmt":"2012-09-15T00:01:00","slug":"weekend-scripter-what-does-a-powershell-module-expose","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-what-does-a-powershell-module-expose\/","title":{"rendered":"Weekend Scripter: What Does a PowerShell Module Expose?"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about identifying what a Windows PowerShell module exposes to the user.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This is it; today is the day for <a href=\"http:\/\/powershellsaturday.com\/002\/\" target=\"_blank\">Windows PowerShell Saturday<\/a> in Charlotte, North Carolina. If you are in the area of the Microsoft Office today, come on by and at least say hi. There are nearly 250 people attending the event, and it is like Woodstock, Burning Man, and the World&rsquo;s Fair all rolled into one huge scripting geek fest. (Oh, by the way, if you are unable to attend the Charlotte, North Carolina Windows PowerShell Saturday, there is another one in <a href=\"http:\/\/powershellsaturday.com\/003\/\" target=\"_blank\">Atlanta, Georgia on October 27, 2012<\/a>. In the coming weeks, I will be posting pictures from the Windows PowerShell Saturday event and from the scripting slumber party (which means finding time to upload the pictures to my computer and sorting through literally hundreds of pics).<\/p>\n<p>One of the cool things about Windows PowerShell modules is that they can contain a number of items. These items include aliases, cmdlets, and functions. To find these things, first use the <b>Get-Module<\/b> cmdlet to retrieve the module, and then examine the properties. A good place to start is to look at the members of the <b>PSModuleInfo<\/b> object. This is shown here. (<b>gm<\/b> is an alias for get-Member.)<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Module *management | gm -MemberType property ex*<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; TypeName: System.Management.Automation.PSModuleInfo<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MemberType Definition<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">ExportedAliases&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedCmdlets&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedCommands&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedFormatFiles Property&nbsp;&nbsp; System.Collections.ObjectModel.ReadOnlyCollection[&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedFunctions&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedTypeFiles&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.ObjectModel.ReadOnlyCollection[&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedVariables&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p style=\"padding-left: 30px\">ExportedWorkflows&nbsp;&nbsp; Property&nbsp;&nbsp; System.Collections.Generic.Dictionary[string,Syste&#8230;<\/p>\n<p>When I see that there are properties for the various things a module might export, I want to examine them. First, notice that these are all collections. This has implications for the way that information returns from the <b>Get-Module<\/b> cmdlet. I like to see what properties are returning anything at all, so an easy way to do that is to pipe the results to the <b>Format-Table<\/b> cmdlet as shown here. (<b>ft<\/b> is an alias for <b>Format-Table<\/b>, and I am choosing properties that begin with the letters <b>ex<\/b>.)<\/p>\n<p>PS C:\\&gt; Get-Module *management | ft ex*<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">ExportedFu ExportedCm ExportedCo ExportedVa ExportedAl ExportedW ExportedF ExportedT<\/p>\n<p style=\"padding-left: 30px\">nctions&nbsp;&nbsp;&nbsp; dlets&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mmands&nbsp;&nbsp;&nbsp;&nbsp; riables&nbsp;&nbsp;&nbsp; iases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; orkflows&nbsp; ormatFile ypeFiles<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">{}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {[Add-C&#8230; {[Add-C&#8230; {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<\/p>\n<p>It appears that only two of the properties return information for the <b>*management<\/b> module, the <b>ExportedCmdlets<\/b> and the <b>ExportedCommands<\/b> properties. Let me hone in on them by using the command shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Module *management | ft exportedc*<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">ExportedCmdlets&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExportedCommands<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">{[Add-Computer, Add-Computer], [Add-Con&#8230; {[Add-Computer, Add-Computer], [Add-Co&#8230;<\/p>\n<p>I see that both properties, <b>ExportedCmdlets<\/b> and <b>ExportedCommands <\/b>return exactly the same information. Therefore, I will focus my efforts on <b>ExportedCmdlets<\/b>. Here is the command I use.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Module *management | Select ExportedCmdlets<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">ExportedCmdlets<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">{[Add-Computer, Add-Computer], [Add-Content, Add-Content], [Checkpoint-Computer, &#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p>Bummer! I do not see all of the exported cmdlets. The reason goes back to the fact that we have a collection, and we are limited by the value of the automatic preference variable, <b>$FormatEnumerationLimit <\/b>(it is set to 4 by default. (For more information about this variable, see <span style=\"text-decoration: underline\"><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/11\/20\/change-a-powershell-preference-variable-to-reveal-hidden-data.aspx\" target=\"_blank\">Change a PowerShell Preference Variable to Reveal Hidden Data<\/a><\/span>.) Without changing the value of <b>$FormatEnumerationLimit<\/b>, the easiest way to see all of the cmdlets is to add the <b>ExpandParameter<\/b><i> <\/i>parameter to the <b>Select-Object<\/b> command. This is shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Module *management | Select -expand ExportedCmdlets<\/p>\n<p>The command and associated output are shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4265.hsg-9-15-12-1.png\"><img decoding=\"async\" title=\"Image of command output\" alt=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4265.hsg-9-15-12-1.png\" \/><\/a><\/p>\n<p>Join me tomorrow when I will talk about more 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: Microsoft Scripting Guy, Ed Wilson, talks about identifying what a Windows PowerShell module exposes to the user. Microsoft Scripting Guy, Ed Wilson, is here. This is it; today is the day for Windows PowerShell Saturday in Charlotte, North Carolina. If you are in the area of the Microsoft Office today, come on by and [&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,364,3,4,45],"class_list":["post-4971","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-powershell-3-0","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about identifying what a Windows PowerShell module exposes to the user. Microsoft Scripting Guy, Ed Wilson, is here. This is it; today is the day for Windows PowerShell Saturday in Charlotte, North Carolina. If you are in the area of the Microsoft Office today, come on by and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4971","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=4971"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4971\/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=4971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}