<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: PowerShell Deep Dive: Using $MyInvocation and Invoke-Expression to support dot-sourcing and direct invocation in shared PowerShell scripts</title>
	<atom:link href="http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/</link>
	<description>Totally addicted to PowerShell</description>
	<lastBuildDate>Sat, 05 May 2012 13:03:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Determine Pipeline Input &#171; The Tech Cafe..</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-2772</link>
		<dc:creator><![CDATA[Determine Pipeline Input &#171; The Tech Cafe..]]></dc:creator>
		<pubDate>Sat, 07 Jan 2012 21:01:48 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-2772</guid>
		<description><![CDATA[[...] upon doing a google search I came across the following article PowerShell Deep Dive: Using $MyInvocation by Kirk Munro which went into great detail on how to use the $MyInvocation variable to make a [...]]]></description>
		<content:encoded><![CDATA[<p>[...] upon doing a google search I came across the following article PowerShell Deep Dive: Using $MyInvocation by Kirk Munro which went into great detail on how to use the $MyInvocation variable to make a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-2270</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Tue, 01 Feb 2011 14:35:18 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-2270</guid>
		<description><![CDATA[Hi Larry,

At the time that this post was written, PowerShell was only available in version 1 which is why I came up with this solution.  In version 2, the module feature was added to PowerShell.  Modules can be loaded/unloaded on demand using Import-Module and Remove-Module, allowing you to load libraries of functions without worrying about whether or not you dot-source them or invoke them directly.  This is the feature you are looking for.

As for examples, I recommend the following:

1. Download and install PowerGUI (you can find that here: &lt;a href=&quot;http://www.powergui.org&quot; rel=&quot;nofollow&quot;&gt;http://www.powergui.org&lt;/a&gt;).
2. Download and install the Module Management Add-on for PowerGUI (you can find that here: &lt;a href=&quot;http://powergui.org/entry.jspa?externalID=2983&amp;categoryID=21&quot; rel=&quot;nofollow&quot;&gt;http://powergui.org/entry.jspa?externalID=2983&amp;categoryID=21&lt;/a&gt;).
3. In the PowerGUI Script Editor, select File &#124; New &#124; Module to create a new module.  This will give you the framework for your module.
4. Now add your functions to your module by putting them in your psm1 file or by dot-sourcing files containing functions.
5. Save your files and load your module.

If you follow these steps, you&#039;ll have a module that you can load and unload on demand.  All functions inside a module are public by default.  If you want private functions, have a look at the PowerShell v2 snippets in PowerGUI (Edit &#124; Insert Snippet, then open the PowerShell v2 container to see the snippets).  There are snippets allowing you to insert whatever type of function you want into your module.

Another alternative for module creation would be to open a script file where you have functions defined and then use the File &#124; Convert to Module menu item (this is also part of the Module Management Add-on).  That will give you a module that automatically contains the functions defined in your script file.

Don&#039;t hesitate to come back with more questions if you have any.

Kirk out.]]></description>
		<content:encoded><![CDATA[<p>Hi Larry,</p>
<p>At the time that this post was written, PowerShell was only available in version 1 which is why I came up with this solution.  In version 2, the module feature was added to PowerShell.  Modules can be loaded/unloaded on demand using Import-Module and Remove-Module, allowing you to load libraries of functions without worrying about whether or not you dot-source them or invoke them directly.  This is the feature you are looking for.</p>
<p>As for examples, I recommend the following:</p>
<p>1. Download and install PowerGUI (you can find that here: <a href="http://www.powergui.org" rel="nofollow">http://www.powergui.org</a>).<br />
2. Download and install the Module Management Add-on for PowerGUI (you can find that here: <a href="http://powergui.org/entry.jspa?externalID=2983&amp;categoryID=21" rel="nofollow">http://powergui.org/entry.jspa?externalID=2983&#038;categoryID=21</a>).<br />
3. In the PowerGUI Script Editor, select File | New | Module to create a new module.  This will give you the framework for your module.<br />
4. Now add your functions to your module by putting them in your psm1 file or by dot-sourcing files containing functions.<br />
5. Save your files and load your module.</p>
<p>If you follow these steps, you&#8217;ll have a module that you can load and unload on demand.  All functions inside a module are public by default.  If you want private functions, have a look at the PowerShell v2 snippets in PowerGUI (Edit | Insert Snippet, then open the PowerShell v2 container to see the snippets).  There are snippets allowing you to insert whatever type of function you want into your module.</p>
<p>Another alternative for module creation would be to open a script file where you have functions defined and then use the File | Convert to Module menu item (this is also part of the Module Management Add-on).  That will give you a module that automatically contains the functions defined in your script file.</p>
<p>Don&#8217;t hesitate to come back with more questions if you have any.</p>
<p>Kirk out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-2268</link>
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 18:16:21 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-2268</guid>
		<description><![CDATA[Thanks...very helpful

What about modular option?  doesn&#039;t powershell support somthing simalar to python modules...if so do you know where to find some examples?

thanks]]></description>
		<content:encoded><![CDATA[<p>Thanks&#8230;very helpful</p>
<p>What about modular option?  doesn&#8217;t powershell support somthing simalar to python modules&#8230;if so do you know where to find some examples?</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1930</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Thu, 11 Nov 2010 01:42:10 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1930</guid>
		<description><![CDATA[Glad I could help! :)]]></description>
		<content:encoded><![CDATA[<p>Glad I could help! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kent dannehl</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1929</link>
		<dc:creator><![CDATA[kent dannehl]]></dc:creator>
		<pubDate>Wed, 10 Nov 2010 23:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1929</guid>
		<description><![CDATA[Thanks Kirk.
This cleared up a large misconception that I didn&#039;t know I had. I thought dot source was .\scriptName.ps1, not . .\scriptName.ps1. 

chagrinedly,
kent]]></description>
		<content:encoded><![CDATA[<p>Thanks Kirk.<br />
This cleared up a large misconception that I didn&#8217;t know I had. I thought dot source was .\scriptName.ps1, not . .\scriptName.ps1. </p>
<p>chagrinedly,<br />
kent</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1924</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Mon, 08 Nov 2010 13:52:40 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1924</guid>
		<description><![CDATA[Hi Kent,

The difference in execution can be seen when you compare dot-sourcing the script to invoking the script using the call operator.

For example, if you created a Test-Invoke.ps1 script file, compare this:

    # Note you must include the leading dot to dot-source the file contents
    . .\Test-Invoke.ps1

to this:

    # In this case the call operator is actually not necessary, I just include it for completeness.
    &amp; .\Test-Invoke.ps1 

In your comment it seems like you were comparing the same thing: using the call operator and invoking the script using the relative path.

Let me know if you get different results by using dot-sourcing.

Thanks,

Kirk out.]]></description>
		<content:encoded><![CDATA[<p>Hi Kent,</p>
<p>The difference in execution can be seen when you compare dot-sourcing the script to invoking the script using the call operator.</p>
<p>For example, if you created a Test-Invoke.ps1 script file, compare this:</p>
<p>    # Note you must include the leading dot to dot-source the file contents<br />
    . .\Test-Invoke.ps1</p>
<p>to this:</p>
<p>    # In this case the call operator is actually not necessary, I just include it for completeness.<br />
    &amp; .\Test-Invoke.ps1 </p>
<p>In your comment it seems like you were comparing the same thing: using the call operator and invoking the script using the relative path.</p>
<p>Let me know if you get different results by using dot-sourcing.</p>
<p>Thanks,</p>
<p>Kirk out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kent Dannehl</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1921</link>
		<dc:creator><![CDATA[Kent Dannehl]]></dc:creator>
		<pubDate>Sun, 07 Nov 2010 02:09:15 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1921</guid>
		<description><![CDATA[This has confused me....And I am not a powershell novice.
What is it supposed to do?
I created a test-invoke.ps1 file exactly like Get-Function.ps1 listing #1 above.
When I run it using either .\test-invoke.ps1 or  &amp; C:\Users\kentd\test-invoke.ps1
I get the output below. This output makes sense as as all I am doing is calling the script. There are no $args. If I add any args to the call (e.g. - joe), there is no change to the output.



Name is required
At C:\Users\kentd\test-invoke.ps1:4 char:32
+     param ([string]$name = $(throw &lt;&lt;&lt;&lt;  &#039;Name is required&#039;) )
    + CategoryInfo          : OperationStopped: (Name is required:String) [], RuntimeException
    + FullyQualifiedErrorId : Name is required


As you can see, I am a bit confused....Can you help?

thanks
kent]]></description>
		<content:encoded><![CDATA[<p>This has confused me&#8230;.And I am not a powershell novice.<br />
What is it supposed to do?<br />
I created a test-invoke.ps1 file exactly like Get-Function.ps1 listing #1 above.<br />
When I run it using either .\test-invoke.ps1 or  &amp; C:\Users\kentd\test-invoke.ps1<br />
I get the output below. This output makes sense as as all I am doing is calling the script. There are no $args. If I add any args to the call (e.g. &#8211; joe), there is no change to the output.</p>
<p>Name is required<br />
At C:\Users\kentd\test-invoke.ps1:4 char:32<br />
+     param ([string]$name = $(throw &lt;&lt;&lt;&lt;  &#039;Name is required&#039;) )<br />
    + CategoryInfo          : OperationStopped: (Name is required:String) [], RuntimeException<br />
    + FullyQualifiedErrorId : Name is required</p>
<p>As you can see, I am a bit confused&#8230;.Can you help?</p>
<p>thanks<br />
kent</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1512</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Wed, 24 Feb 2010 21:39:33 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1512</guid>
		<description><![CDATA[Actually Mike they are valid single-quotes.  They just look like back ticks.  Seems to be a font issue.  You can copy and paste any of the code in the article though, and the single quotes will be treated as single quotes and the back ticks will be treated as back ticks.  Sorry for the confusion.]]></description>
		<content:encoded><![CDATA[<p>Actually Mike they are valid single-quotes.  They just look like back ticks.  Seems to be a font issue.  You can copy and paste any of the code in the article though, and the single quotes will be treated as single quotes and the back ticks will be treated as back ticks.  Sorry for the confusion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-1511</link>
		<dc:creator><![CDATA[Mike]]></dc:creator>
		<pubDate>Wed, 24 Feb 2010 21:09:06 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-1511</guid>
		<description><![CDATA[the single quotes in your code are actually back ticks]]></description>
		<content:encoded><![CDATA[<p>the single quotes in your code are actually back ticks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk Munro</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-905</link>
		<dc:creator><![CDATA[Kirk Munro]]></dc:creator>
		<pubDate>Tue, 30 Dec 2008 00:31:24 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-905</guid>
		<description><![CDATA[Thanks for the feedback Ben.  Can you elaborate on what difficulty you are having in copying my code?]]></description>
		<content:encoded><![CDATA[<p>Thanks for the feedback Ben.  Can you elaborate on what difficulty you are having in copying my code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Langton</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-904</link>
		<dc:creator><![CDATA[Ben Langton]]></dc:creator>
		<pubDate>Mon, 29 Dec 2008 23:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-904</guid>
		<description><![CDATA[Nice post.  Thanks for the good information.  You seem to have made it difficult to copy your code, though...]]></description>
		<content:encoded><![CDATA[<p>Nice post.  Thanks for the good information.  You seem to have made it difficult to copy your code, though&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PowerShell script modularization &#171; Left Lobe Logic</title>
		<link>http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/#comment-789</link>
		<dc:creator><![CDATA[PowerShell script modularization &#171; Left Lobe Logic]]></dc:creator>
		<pubDate>Tue, 10 Jun 2008 07:34:51 +0000</pubDate>
		<guid isPermaLink="false">http://kirkmunro.wordpress.com/?p=94#comment-789</guid>
		<description><![CDATA[[...] See Kirk&#8217;s great post on invoking or calling scripts within scripts [...]]]></description>
		<content:encoded><![CDATA[<p>[...] See Kirk&#8217;s great post on invoking or calling scripts within scripts [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

