{"id":8047,"date":"2015-08-19T05:00:00","date_gmt":"2015-08-19T12:00:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=8047"},"modified":"2015-08-13T16:15:28","modified_gmt":"2015-08-13T23:15:28","slug":"get-commands-in-a-nested-module","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2015\/08\/19\/get-commands-in-a-nested-module\/","title":{"rendered":"Get Commands in a Nested Module"},"content":{"rendered":"<p>Many Windows PowerShell modules include nested modules. In fact, some of your favorite cmdlets might be in a nested module, but you wouldn\u2019t typically know it. Nested modules are reusable, so you can repackage and use nested modules independently and in other modules, unless, of course, they require something in the parent module. For example, you can use a nested module in a <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/hh847817.aspx\">custom session configuration<\/a> when the user doesn\u2019t need and shouldn\u2019t have the entire module.<\/p>\n<p>The ModuleInfo and ModuleInfoGrouping objects that the Get-Module cmdlet returns have a NestedModules property. So, to find modules with nested modules, use this command:<\/p>\n<pre lang=\"PowerShell\">Get-Module \u2013ListAvailable | where NestedModules<\/pre>\n<p>To find the nested modules in a particular module, use a command with this format:<\/p>\n<pre lang=\"PowerShell\">(Get-Module \u2013ListAvailable $ModuleName).NestedModules<\/pre>\n<p>For example, the NetAdapter module has 19 nested modules. (CIM modules typically have lots of nested modules.)<\/p>\n<pre class=\"output\">PS C:\\&gt; (Get-Module -ListAvailable NetAdapter).NestedModules\r\n\r\nModuleType Version\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ExportedCommands\r\n---------- -------\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ----------------\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapter.cmdletDefinition\u00a0\u00a0\u00a0 {Get-NetAdapter, Enable-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterAdvancedProperty.... {Get-NetAdapterAdvancedPr\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterBinding.cmdletDef... {Get-NetAdapterBinding, S\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterChecksumOffload\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterChecksumOf\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterEncapsulatedPacke... {Get-NetAdapterEncapsulat\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterHardwareInfo.cmdl... Get-NetAdapterHardwareInf\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterIPsecOffload\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterIPsecOfflo\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterLso\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterLso, Set-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterPowerManagement.c... {Get-NetAdapterPowerManag\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterQos\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterQos, Set-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterRdma\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterRdma, Set-\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterRsc\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterRsc, Set-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterRss.cmdletDefinition {Get-NetAdapterRss, Set-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterSriov\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Get-NetAdapterSriov, Set\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterSriovVf.cmdletDef... Get-NetAdapterSriovVf\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterStatistics.cmdlet... Get-NetAdapterStatistics\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterVmq.cmdletDefinition {Get-NetAdapterVmq, Set-N\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterVmqQueue.cmdletDe... Get-NetAdapterVmqQueue\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterVPort.cmdletDefin... Get-NetAdapterVPort\r\n<\/pre>\n<p>Sadly, you can\u2019t use Module parameter of Get-Command to get the commands in a nested module.<\/p>\n<pre class=\"output\">PS C:\\> Get-Command -Module MSFT_NetAdapterQos\r\nPS C:\\>\r\n<\/pre>\n<p>But, it\u2019s easy to get them. The NestedModules property contains a ReadOnlyCollection of PSModuleInfo objects. Each one has all of the Exported properties of any module, including ExportedCmdlets, ExportedFunctions, and ExportedCommands, which includes all exported command types. <\/p>\n<pre lang=\"PowerShell\">(Get-Module NetAdapter -ListAvailable).NestedModules | \r\n    Format-Table \u2013Property Name, ExportedCommands \u2013Wrap<\/pre>\n<p>The ExportedCommands are in dictionaries (like a hash table), so, to get the commands in a given nested module, use a command like this one:<\/p>\n<pre lang=\"PowerShell\">((Get-Module $ModuleName \u2013ListAvailable).NestedModules | \r\n    where Name \u2013eq $NestedModuleName).ExportedCommands.Keys<\/pre>\n<p>For example:<\/p>\n<pre class=\"output\">\r\nPS C:\\&gt; ((Get-Module -ListAvailable NetAdapter).NestedModules |\r\nwhere Name -eq MSFT_NetAdapterQos).ExportedCommands.Keys\r\n\r\nGet-NetAdapterQos\r\nSet-NetAdapterQos\r\nEnable-NetAdapterQos\r\nDisable-NetAdapterQos\r\n<\/pre>\n<p>You can also find out which nested module exports a particular command:<\/p>\n<pre class=\"output\">\r\nPS C:\\&gt; (Get-Module \u2013ListAvailable NetAdapter).NestedModules |\r\nwhere {$_.ExportedCommands.Keys -eq \"Enable-NetAdapterQos\"} \r\n\r\nModuleType Version\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ExportedCommands\r\n---------- -------\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0----------------\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterQos\u00a0\u00a0\u00a0{Get-NetAdapterQos, Set-NetAdapterQos, Enable-NetAdapterQos\r\n<\/pre>\n<p>To get the source file for a nested module, look in the value of its <b>Path<\/b> property.<\/p>\n<pre class=\"output\">\r\nPS C:\\> (Get-Module NetAdapter -ListAvailable).NestedModules | Format-List Name, Path\r\n\r\nName : MSFT_NetAdapter.cmdletDefinition\r\nPath : C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\NetAdapter\\MSFT_NetAdapter.cmdletDef\r\n\r\nName : MSFT_NetAdapterAdvancedProperty.cmdletDefinition\r\nPath : C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\NetAdapter\\MSFT_NetAdapterAdvancedPr\r\n\r\nName : MSFT_NetAdapterQos\r\nPath : C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\NetAdapter\\MSFT_NetAdapterQos.cdxml\r\n...\r\n<\/pre>\n<p>And, use the Path value to import the module.<\/p>\n<pre class=\"output\">\r\nPS C:\\&gt; Import-Module $pshome\\Modules\\NetAdapter\\MSFT_NetAdapterQos.cdxml\r\n\r\nPS C:\\&gt; Get-Module\r\n\r\nModuleType Version\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ExportedCommands\r\n---------- -------\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ----------------\r\nManifest\u00a0\u00a0 3.1.0.0\u00a0\u00a0\u00a0 Microsoft.PowerShell.Management\u00a0\u00a0\u00a0\u00a0 {Add-Computer, Add-Conte\r\nManifest\u00a0\u00a0 3.1.0.0\u00a0\u00a0\u00a0 Microsoft.PowerShell.Utility\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Add-Member, Add-Type, C\r\nCim\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MSFT_NetAdapterQos\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {Disable-NetAdapterQos,<\/span><\/blockquote>\r\n<\/pre>\n<p>Be sure to test, because many nested modules require other modules.<\/p>\n<p><i>June Blender is a technology evangelist at SAPIEN Technologies, Inc. and a Windows PowerShell MVP. You can reach her at <a href=\"mailto:juneb@sapien.com\">juneb@sapien.com<\/a> or follow her on Twitter at <a href=\"https:\/\/twitter.com\/juneb_get_help\">@juneb_get_help<\/a>.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many Windows PowerShell modules include nested modules. In fact, some of your favorite cmdlets might be in a nested module, but you wouldn\u2019t typically know it. Nested modules are reusable, so you can repackage and use nested modules independently and in other modules, unless, of course, they require something in the parent module. For example, [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[934,28,1001],"class_list":["post-8047","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-juneb","tag-powershell","tag-tip"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/8047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=8047"}],"version-history":[{"count":8,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/8047\/revisions"}],"predecessor-version":[{"id":9672,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/8047\/revisions\/9672"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=8047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=8047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=8047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}