<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; Import-Module</title>
	<atom:link href="http://joelbennett.net/tag/import-module/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelbennett.net</link>
	<description>The internet home of Joel "Jaykul" Bennett...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='joelbennett.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Get-Command in PowerShell 3 (NOTE: CTP2 Bug causes module loading)</title>
		<link>http://joelbennett.net/get-command-in-powershell-3/</link>
		<comments>http://joelbennett.net/get-command-in-powershell-3/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 06:16:29 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Get-Command]]></category>
		<category><![CDATA[Import-Module]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1813</guid>
		<description><![CDATA[I don&#8217;t normally blog about the bugs I find in beta software, but I posted this bug to PowerShell&#8217;s Connect and I feel like it got ignored and not voted, so I&#8217;m going to try to explain myself better here &#8230; The bug is on Connect, but let me talk to you first about how [...]]]></description>
			<content:encoded><![CDATA[	<p>I don&#8217;t normally blog about the bugs I find in beta software, but I posted this bug to PowerShell&#8217;s Connect and I feel like it got ignored and not voted, so I&#8217;m going to try to explain myself better here &#8230; The <a href="https://connect.microsoft.com/PowerShell/feedback/details/724659/passing-a-module-array-to-get-command-imports-modules">bug is on Connect</a>, but let me talk to you first about how <code>Get-Command</code> is supposed to work.</p>

	<p>In PowerShell, <code>Get-Command</code> is a command that serves two purposes: first it lets you search for commands using verb, noun, wildcards, module names etc. and then it also returns metadata about commands.  In PowerShell 2, it could only search commands that were in modules (or snapins) you had already imported, or executables &#038; scripts that were in your <span class="caps">PATH</span>. </p>

	<p>So here&#8217;s the deal: <code>Get-Command</code> has always behaved differently when it thinks you&#8217;re searching.  The only way it can tell that you&#8217;re searching is that you don&#8217;t provide a full command name. So, if you use a wildcard (e.g.: <code>Get-Command Get-Acl*</code> or even <code>Get-Command Get-Ac[l]</code>), or search using a Noun or Verb (e.g.: <code>Get-Command -Verb Get</code> or <code>Get-Command -Noun Acl</code> or even <code>Get-Command -Verb Get -Noun Acl</code>), then PowerShell assumes you&#8217;re searching (and won&#8217;t throw an error when no command is found).  </p>

	<p>In PowerShell 3, because modules can be loaded automatically when you try to run a command from them, <code>Get-Command</code> had to be modified to be able to return commands that aren&#8217;t already loaded.  The problem the PowerShell team faced is that in order to get the metadata about a command, they needed to actually import the module. What they came up with is that if you&#8217;re searching &#8230; then Get-Command will <em>not</em> load modules which aren&#8217;t already loaded.  If you specify a full command name with no wildcards, then PowerShell will load any module(s) where it finds a matching command in order to get the metadata (parameter sets, assembly info, help, etc). And of course, if you specify a full command that doesn&#8217;t exist, you&#8217;ll get an error!</p>

	<p>Perhaps a few examples will help:</p>

	<p>Launch <strong>PowerShell 3</strong> using: </p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">powershell</span> <span style="color: #000066;">-noprofile</span> <span style="color: #000066;">-noexit</span> <span style="color: #000066;">-command</span> <span style="color: #009900;">&quot;function prompt {'[$($myinvocation.historyID)]: '}&quot;</span><br />
&nbsp;</div>

	<p>And then try this, noticing how much more information you get when you specify a specific full name:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #000066;">-Verb</span> Get <span style="color: #000066;">-Noun</span> Acl <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Format-<span style="font-style: normal;">List</span></span><br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Capability &nbsp; &nbsp; &nbsp; : Cmdlet<br />
Definition &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Path &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
AssemblyInfo &nbsp; &nbsp; :<br />
DLL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />
HelpFile &nbsp; &nbsp; &nbsp; &nbsp; :<br />
ParameterSets &nbsp; &nbsp;: <span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
ImplementingType :<br />
Verb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Get<br />
Noun &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Acl<br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Format-<span style="font-style: normal;">List</span></span><br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Capability &nbsp; &nbsp; &nbsp; : Cmdlet<br />
Definition &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Path<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-InputObject</span> <span style="color: #66cc66;">&lt;</span>psobject<span style="color: #66cc66;">&gt;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>LiteralPath<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
Path &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
AssemblyInfo &nbsp; &nbsp; :<br />
DLL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: C:\Windows\Microsoft.<span style="color: #003366;">Net</span>\assembly\GAC_MSIL\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v4.0_3.0.0.0__31bf3856ad364e35\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>.<span style="color: #003366;">dll</span><br />
HelpFile &nbsp; &nbsp; &nbsp; &nbsp; : Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>.<span style="color: #003366;">dll</span><span style="color: #66cc66;">-</span><span style="color: #660033;">Help</span>.<span style="color: #003366; font-weight: bold;">xml</span><br />
ParameterSets &nbsp; &nbsp;: <span style="color: #333;">&#123;</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Path<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-InputObject</span> <span style="color: #66cc66;">&lt;</span>psobject<span style="color: #66cc66;">&gt;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>LiteralPath<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#125;</span><br />
ImplementingType : Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Commands</span>.<span style="color: #003366;">GetAclCommand</span><br />
Verb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Get<br />
Noun &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Acl<br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">ConvertFrom-<span style="font-style: normal;">Sec</span></span>...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h3>But there are several problems:</h3>

	<p><code>Get-Command</code> has another parameter: <code>-Module</code>, which allows you to specify which modules should be searched, and in PowerShell 3, it changes the behavior in weird (buggy) ways:</p>

	<ol>
		<li>If you specify a single module, then that module is imported (to search it more thoroughly?), <em>even if you specify a <strong>specific</strong> command that&#8217;s <strong>not</strong> in that module</em>.</li>
		<li>If you specify a single module that does <strong>not</strong> have a command that matches, then Microsoft.PowerShell.Management is loaded <em>also</em>. I don&#8217;t know why yet.</li>
		<li>If you specify more than one module, <em>and you&#8217;re searching</em>, and none of them have a command that matches &#8230; it&#8217;s just as though you hadn&#8217;t specified modules, and nothing unexpected happens.
		<li>If you specify more than one module, <em>and a specific command</em>, then it gets <strong>really wierd</strong>:
	<ul>
		<li>If the command <em>is</em> in one (or more) of the specified modules,  the first module (in <span class="caps">PATH</span> order, not the order you specified) which you listed that has the command is imported.</li>
	</ul></li>
	<ul>
		<li>If it&#8217;s a valid command in a different module, the first module with the command is loaded &#8230; and so is Microsoft.PowerShell.Management. I don&#8217;t know why! Oh, and you still get the error because it can&#8217;t find the command where you told it to look.</li>
	</ul></li>
	</ol>
	<ol>
		<li></li>
	</ol>

	<p>I <a href="https://connect.microsoft.com/PowerShell/feedback/details/724659/passing-a-module-array-to-get-command-imports-modules">filed a bug on Connect</a> to cover that last scenario where the module containing the command is loaded even though you gave Get-Command a list of modules to look in, here&#8217;s another example, and notice that even though all I do here is run the same command over and over (I added some Get-Module to show you <span class="caps">WHY</span> you get these results, but it&#8217;s the same without them), but I get different results:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># Passes one module</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> : The term <span style="color: #009900;">'get-acl'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> recognized <span style="color: #333399; font-weight: bold; font-style: italic;">as</span> the name of a <br />
cmdlet, <span style="color: #666699; font-weight: bold;">function</span>, script file, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> operable program. <span style="color: #003366;">Check</span> the <br />
spelling of the name, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> <span style="color: #666699; font-weight: bold;">if</span> a path was included, verify that the <br />
path <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> correct <span style="color: #333399; font-weight: bold; font-style: italic;">and</span> <span style="color: #666699; font-weight: bold;">try</span> again.<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Management</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Computer</span></span>, ...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># Passes two modules </span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> : The term <span style="color: #009900;">'get-acl'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> recognized <span style="color: #333399; font-weight: bold; font-style: italic;">as</span> the name of a <br />
cmdlet, <span style="color: #666699; font-weight: bold;">function</span>, script file, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> operable program. <span style="color: #003366;">Check</span> the <br />
spelling of the name, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> <span style="color: #666699; font-weight: bold;">if</span> a path was included, verify that the <br />
path <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> correct <span style="color: #333399; font-weight: bold; font-style: italic;">and</span> <span style="color: #666699; font-weight: bold;">try</span> again.<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Management</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Computer</span></span>, ...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">ConvertFrom-<span style="font-style: normal;">Sec</span></span>...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #333;">&#93;</span>: <span style="color: #666666; font-style: italic;"># This time it will include Microsoft.PowerShell.Security!</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <br />
<br />
Capability &nbsp; &nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ModuleName<br />
<span style="color: #66cc66;">----------</span> &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------</span><br />
Cmdlet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/get-command-in-powershell-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving the “failed to grant minimum permission requests” error</title>
		<link>http://joelbennett.net/solving-the-failed-to-grant-minimum-permission-requests-error/</link>
		<comments>http://joelbennett.net/solving-the-failed-to-grant-minimum-permission-requests-error/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 02:47:08 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Code Access Security]]></category>
		<category><![CDATA[Import-Module]]></category>
		<category><![CDATA[Network Share]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RemoteSigned]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1593</guid>
		<description><![CDATA[If you&#8217;re getting the error: Import-Module : Could not load file or assembly &#8230; or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0&#215;80131417) because you&#8217;re trying to load a module from a network share &#8230; you need to read the PoshCode wiki page which explains how to use caspol [...]]]></description>
			<content:encoded><![CDATA[	<p>If you&#8217;re getting the error: <span style="color:red;">Import-Module : <a href="http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Importing_Binary_Modules_from_Network_Shares">Could not load file or assembly</a> &#8230; or one of its dependencies. <a href="http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Importing_Binary_Modules_from_Network_Shares">Failed to grant minimum permission requests</a>. (Exception from HRESULT: 0&#215;80131417)</span> because you&#8217;re trying to <a href="http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Importing_Binary_Modules_from_Network_Shares">load a module from a network share</a> &#8230; you need to read the PoshCode wiki page which explains how to use caspol to set the <acronym title="Code Access Security">CAS</acronym> policy for a <span class="caps">UNC</span> path file share.</p>

	<p>I feel like I should apologize for this post, since it basically just serves to link to that wiki page, but people keep asking, and my blog has better pagerank than the wiki  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/solving-the-failed-to-grant-minimum-permission-requests-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Module Manifest Gotcha</title>
		<link>http://joelbennett.net/another-module-manifest-gotcha/</link>
		<comments>http://joelbennett.net/another-module-manifest-gotcha/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 03:42:36 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Error message]]></category>
		<category><![CDATA[Globally Unique Identifier]]></category>
		<category><![CDATA[Import-Module]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RequiredModules]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1386</guid>
		<description><![CDATA[Shay Levy, ScriptFanatic, wrote about the PowerShellHostVersion on his blog this morning, explaining how it is not a field you should use in your module manifests. Of course, there&#8217;s an exception: if your module is dependent on a specific host. For instance, if you&#8217;ve written a module for PoshConsole which exploits the WpfHost display features [...]]]></description>
			<content:encoded><![CDATA[	<p>Shay Levy, ScriptFanatic, wrote <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2010/01/14/module-manifest-gotcha.aspx">about the PowerShellHostVersion</a> on his blog this morning, explaining how it is <strong>not</strong> a field you should use in your <a href="http://msdn.com/library/dd878337.aspx">module manifests</a>.</p>

	<p>Of course, there&#8217;s an exception: if your module is dependent on a specific host.  For instance, if you&#8217;ve written a module for <a href="http://poshconsole.codeplex.com">PoshConsole</a> which exploits the WpfHost display features or the BgHost hotkeys feature &#8230; or if you&#8217;ve written <a href="http://code.msdn.microsoft.com/PowerShellPack">ISEPack</a> based on the menu and script-editor features of PowerShell <span class="caps">ISE</span>), then it makes sense to specify the <strong>PowerShellHostName</strong> and the <strong>PowerShellHostVersion</strong> together.  However, if you aren&#8217;t taking a dependency on a specific host &#8230; you should definitely <strong>never</strong> specify PowerShellHostVersion by itself.</p>

	<h3>RequiredModules</h3>

	<p>I&#8217;ve got another one that I think you should not use. PowerShell has several ways of specifying prerequisites for your modules, such as assemblies that should be loaded, modules that must be nested, etc. In every case <strong>except</strong> RequiredModules, PowerShell will actually import those things for you.</p>

	<p>That is, if you specify that you RequiredAssemblies = &#8220;System.Windows.Forms&#8221; it will automatically load it. If you specify NestedModules = &#8220;BitsTransfer&#8221; it will automatically load that. But if you specify RequiredModules = &#8220;BitsTransfer&#8221; you&#8217;re sore out of luck.</p>

	<p>Not only does PowerShell not load them for you, it doesn&#8217;t give you all the information you need to load them when it fails. For example, consider that you have a module called &#8220;ReallyRequired&#8221; and one called &#8220;TestModule&#8221; which requires ReallyRequired.  It&#8217;s metadata file is very simple, it looks like this:</p>

	<div class="posh code posh" style="font-family:monospace;">@<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; Author<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Joel Bennett&quot;</span><br />
&nbsp; &nbsp; ModuleToProcess<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;TestModule.psm1&quot;</span>; ModuleVersion<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;1.0.0.0&quot;</span><br />
&nbsp; &nbsp; RequiredModules<span style="color: #66cc66;">=</span>@<span style="color: #333;">&#123;</span>ModuleName<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;ReallyRequired&quot;</span>;GUID<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;84b5ab08-3620-4f72-bffd-44d2a6bb506d&quot;</span>; ModuleVersion<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;2.5.0.0&quot;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>Before we try to import it, we might try to check which modules it requires, and since it doesn&#8217;t appear to require any, we&#8217;ll go ahead and import it:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">get-<span style="font-style: normal;">module</span></span> <span style="color: #000066;">-list</span> TestModule <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> RequiredModule<br />
<br />
RequiredModules &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; <br />
<span style="color: #66cc66;">---------------</span> &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; <br />
<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> TestModule<br />
<br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> : The required module <span style="color: #009900;">'ReallyRequired'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> loaded. <span style="color: #003366;">Load</span> the module <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> remove the module <span style="color: #666699; font-weight: bold;">from</span> <span style="color: #009900;">'RequiredModules'</span> <span style="color: #666699; font-weight: bold;">in</span> the file <span style="color: #009900;">'C:\Users\Joel\Documents\WindowsPowerShell\Modules\TestModule\TestModule.psd1'</span>.</div>

	<p>Apparently, there&#8217;s just no way to tell which module(s) you need to preload (or even whether there are any) until you get an error message. You might think you could just write a script to test for that error and then run <code>Import-Module ReallyRequired</code> &#8230; but what you don&#8217;t know is that after you load your copy of the ReallyRequired module:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: ImportModule TestModule<br />
<br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> : The required module <span style="color: #009900;">'ReallyRequired'</span> with version <span style="color: #009900;">'2.5.0.0'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> loaded. <span style="color: #003366;">Load</span> the module <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> remove the module <span style="color: #666699; font-weight: bold;">from</span> <span style="color: #009900;">'RequiredModules'</span> <span style="color: #666699; font-weight: bold;">in</span> the file <span style="color: #009900;">'C:\Users\Joel\Documents\WindowsPowerShell\Modules\TestModule\TestModule.psd1'</span>.</div>

	<p>If you&#8217;re like me, right now you&#8217;re tearing out your hair wondering why the error message didn&#8217;t tell you that in the first place. Then you have to go off and try to find a newer version of your RequiredModules. And that&#8217;s not even the crazy thing! The crazy thing is, if you find the wrong one, you could still get a message about the <span class="caps">GUID</span> not matching next.  <img src='http://joelbennett.net/wordpress/wp-includes/' alt='8-O' class='wp-smiley' /> </p>

	<p>So yeah, RequiredModules is really unlikely to be helpful right now. You&#8217;re better off just putting an <code>Import-Module ReallyRequired -version 2.5 -ErrorAction Stop</code> at the top of you script module (although that won&#8217;t help you if you&#8217;re writing a binary cmdlet module).</p>

	<h3>Some good news</h3>

	<p>This is just one of the things that the new PoshCode is being designed to address, so I&#8217;ll be blogging more about this shortly, but for now, you can use this function to list RequiredModules:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">RequiredModules</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Path</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Content</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$Path</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-delim</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">char</span><span style="color: #333;">&#93;</span></span><span style="color: #cc66cc;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;">## We are ONLY going to &quot;Tokenize&quot; this to make sure there isn't an extra &quot;}&quot; which could lead to an exploit:</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Management.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSParser</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Tokenize</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;&quot;</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ref</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$null</span><span style="color: #333;">&#41;</span> &nbsp;<span style="color: #666666; font-style: italic;"># work around a PowerShell BUG</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ParseErrors</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #009900;">&quot;System.Collections.ObjectModel.Collection[System.Management.Automation.PSParseError]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:tokens <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Management.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSParser</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Tokenize</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$dataSource</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ref</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$ParseErrors</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ParseErrors</span>.<span style="color: #003366;">Count</span> <span style="color: #000066;">-gt</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ParseErrors</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;$($_.Message)<span style="color: #000099; font-weight: bold;">`n</span>$File at line:$($_.Token.StartLine) char:$($_.Token.Start)&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #000066;">-replace</span> <span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span># SIG #&quot;</span>,<span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span> # SIG #&quot;</span><br />
<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Expression</span></span> <span style="color: #009900;">&quot;DATA {<span style="color: #000099; font-weight: bold;">`n</span> $dataSource <span style="color: #000099; font-weight: bold;">`n</span>}&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">RequiredModules</span><br />
<span style="color: #333;">&#125;</span></div>

<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/a-question-about-powershell-module-manifests/">A question about PowerShell Module Manifests</a> (huddledmasses.org)</li></ul>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bf32d64f-fae9-4f34-ab85-385a6242e5ba/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bf32d64f-fae9-4f34-ab85-385a6242e5ba" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/another-module-manifest-gotcha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

