<?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/"
		>
<channel>
	<title>Comments on: Why would I want to call a function that exists in a separate script?</title>
	<atom:link href="http://www.powershellpro.com/function-calling/144/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellpro.com/function-calling/144/</link>
	<description>Sharing the Experience</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:09:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-1151</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 24 Jan 2012 18:41:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-1151</guid>
		<description>I&#039;m not sure if anyone is still reading this thread, but another option is to include your favorite functions as global functions in the profile file. This way the functions are always available within the PS environment and do not need to be sourced in each script. Of course, this should only be done for those functions to which you frequently need access.

To find the profile file, check the value of $profile.

Add your functions with the global desgination:

Function Global:myFunction($var1,$var2){
   #Do something here
   Return $result
}</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure if anyone is still reading this thread, but another option is to include your favorite functions as global functions in the profile file. This way the functions are always available within the PS environment and do not need to be sourced in each script. Of course, this should only be done for those functions to which you frequently need access.</p>
<p>To find the profile file, check the value of $profile.</p>
<p>Add your functions with the global desgination:</p>
<p>Function Global:myFunction($var1,$var2){<br />
   #Do something here<br />
   Return $result<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahmoud</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-720</link>
		<dc:creator>Mahmoud</dc:creator>
		<pubDate>Tue, 08 Nov 2011 20:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-720</guid>
		<description>I am trying to call another script responsible to send a mail. however, when I put &#039;send email logic&#039; inside a function 
it is not working or more precisely it is running but not receiving the email. when the send email logic is not in a function (just written in the script), it is actually working. here is the code

not working code
function send($from,$to)
{
	try 
		{  
			$messageParameters = @{
			smtpServer = “smtphost”
			From = $from
			To = $to
			Subject = ”You Submitted a Job”
			Body = ”You Job Chain is submitted successfully”
			}
			Send-MailMessage @messageParameters -BodyAsHtml 
		}
		catch 
		{
			write-host &quot;======================================================================&quot; -ForegroundColor green
			write-host &#039;sending email is failed&#039; -ForegroundColor green
			write-host &quot;======================================================================&quot; -ForegroundColor green
		}
}

and the working code is


	try 
		{  
			$messageParameters = @{
			smtpServer = “smtphost”
			From = $from
			To = $to
			Subject = ”You Submitted a Job”
			Body = ”You Job Chain is submitted successfully”
			}
			Send-MailMessage @messageParameters -BodyAsHtml 
		}
		catch 
		{
			write-host &quot;======================================================================&quot; -ForegroundColor green
			write-host &#039;sending email is failed&#039; -ForegroundColor green
			write-host &quot;======================================================================&quot; -ForegroundColor green
		}</description>
		<content:encoded><![CDATA[<p>I am trying to call another script responsible to send a mail. however, when I put &#8217;send email logic&#8217; inside a function<br />
it is not working or more precisely it is running but not receiving the email. when the send email logic is not in a function (just written in the script), it is actually working. here is the code</p>
<p>not working code<br />
function send($from,$to)<br />
{<br />
	try<br />
		{<br />
			$messageParameters = @{<br />
			smtpServer = “smtphost”<br />
			From = $from<br />
			To = $to<br />
			Subject = ”You Submitted a Job”<br />
			Body = ”You Job Chain is submitted successfully”<br />
			}<br />
			Send-MailMessage @messageParameters -BodyAsHtml<br />
		}<br />
		catch<br />
		{<br />
			write-host &#8220;======================================================================&#8221; -ForegroundColor green<br />
			write-host &#8217;sending email is failed&#8217; -ForegroundColor green<br />
			write-host &#8220;======================================================================&#8221; -ForegroundColor green<br />
		}<br />
}</p>
<p>and the working code is</p>
<p>	try<br />
		{<br />
			$messageParameters = @{<br />
			smtpServer = “smtphost”<br />
			From = $from<br />
			To = $to<br />
			Subject = ”You Submitted a Job”<br />
			Body = ”You Job Chain is submitted successfully”<br />
			}<br />
			Send-MailMessage @messageParameters -BodyAsHtml<br />
		}<br />
		catch<br />
		{<br />
			write-host &#8220;======================================================================&#8221; -ForegroundColor green<br />
			write-host &#8217;sending email is failed&#8217; -ForegroundColor green<br />
			write-host &#8220;======================================================================&#8221; -ForegroundColor green<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-707</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Tue, 18 Oct 2011 05:13:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-707</guid>
		<description>Hey, I wonder can I use this on StrageyDesk from TD Ameritrade.
I am trying to build a libuary of routeens and functions and call them with out putting all in the editor.</description>
		<content:encoded><![CDATA[<p>Hey, I wonder can I use this on StrageyDesk from TD Ameritrade.<br />
I am trying to build a libuary of routeens and functions and call them with out putting all in the editor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joachim</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-687</link>
		<dc:creator>Joachim</dc:creator>
		<pubDate>Fri, 09 Sep 2011 09:20:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-687</guid>
		<description>When i use the . method to include a script with functions all works fine until I run it with task scheduler (Server 2008 R2). All scripts then end with a 0x41306. Before I used the . to incldude functions the tasks worked fine. Running them directly is fine too.

That&#039;s how I include my functions
. \\servername\scripts$\library.ps1

Do you have any idea how I can get this to work with the task scheduler?

Cheers
Joachim</description>
		<content:encoded><![CDATA[<p>When i use the . method to include a script with functions all works fine until I run it with task scheduler (Server 2008 R2). All scripts then end with a 0&#215;41306. Before I used the . to incldude functions the tasks worked fine. Running them directly is fine too.</p>
<p>That&#8217;s how I include my functions<br />
. \\servername\scripts$\library.ps1</p>
<p>Do you have any idea how I can get this to work with the task scheduler?</p>
<p>Cheers<br />
Joachim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-642</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Thu, 16 Jun 2011 08:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-642</guid>
		<description>Hi Jesse!

I am currently reorganizing my scripts to your function approach.
I just want to know if you can tell me where to insert the

Start-SPAssignment -Global
Stop-SPAssignment -Global

commands. As of before, I placed the start right at the beginning of each of my scripts and the stop at the very end. Where do I place them in a .ps1 file filled with functions? Is it in each functions beginning and end or just at the beginning and end of the .ps1 file, thereby maybe encapsulating all functions?

with kind regards,
Andy</description>
		<content:encoded><![CDATA[<p>Hi Jesse!</p>
<p>I am currently reorganizing my scripts to your function approach.<br />
I just want to know if you can tell me where to insert the</p>
<p>Start-SPAssignment -Global<br />
Stop-SPAssignment -Global</p>
<p>commands. As of before, I placed the start right at the beginning of each of my scripts and the stop at the very end. Where do I place them in a .ps1 file filled with functions? Is it in each functions beginning and end or just at the beginning and end of the .ps1 file, thereby maybe encapsulating all functions?</p>
<p>with kind regards,<br />
Andy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-621</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Sun, 15 May 2011 14:50:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-621</guid>
		<description>Eric,
If you want functions available to every instance of Powershell.exe, I think you would have to put them your profile files or dot source them in your profile files. Type
help profile
in Powershell to learn about the profile files.</description>
		<content:encoded><![CDATA[<p>Eric,<br />
If you want functions available to every instance of Powershell.exe, I think you would have to put them your profile files or dot source them in your profile files. Type<br />
help profile<br />
in Powershell to learn about the profile files.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Duncan</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-470</link>
		<dc:creator>Eric Duncan</dc:creator>
		<pubDate>Fri, 09 Apr 2010 18:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-470</guid>
		<description>This is great but I have an issue: Using the example above, the first script (which has the function) also launches a new powershell.exe instance, the second script in the new instance does not seem to be able to call the function in the first script. Is there a way around this?</description>
		<content:encoded><![CDATA[<p>This is great but I have an issue: Using the example above, the first script (which has the function) also launches a new powershell.exe instance, the second script in the new instance does not seem to be able to call the function in the first script. Is there a way around this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Trotter</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-451</link>
		<dc:creator>Marc Trotter</dc:creator>
		<pubDate>Sat, 13 Mar 2010 18:56:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-451</guid>
		<description>Is there a way to loop through subfolders and call a script named run.ps1 from below each folder.  I&#039;m fairly new to powershell and can&#039;t get this to work. As presently written it simply treats the file as a literal string, not really what I&#039;m after.

I want to place a script and all supporting files in a subfolder and then loop through each subfolder and call run.ps1.  This is what I presently do with CMD files, that way when I no longer need a module we just delete the folder.  Similarly if I need to add a module I just drop in a new folder.  I don&#039;t want to edit the calling script, if I can avoid it.

Here&#039;s what I have:

   $list = Get-ChildItem C:\APPS\SCRIPTS -exclude maintenance.ps1 &#124; Sort-Object Name
   
   foreach ($i in $list)
      {
         Write-Host &quot;Processing &quot; $i&quot;...&quot;
         $sScript = [STRING]$i + &quot;\run.ps1&quot;
       # this line works
         .{c:\apps\scripts00_Critical\run.ps1}
       # this line doesn&#039;t work
         .{$sScript}
      }</description>
		<content:encoded><![CDATA[<p>Is there a way to loop through subfolders and call a script named run.ps1 from below each folder.  I&#8217;m fairly new to powershell and can&#8217;t get this to work. As presently written it simply treats the file as a literal string, not really what I&#8217;m after.</p>
<p>I want to place a script and all supporting files in a subfolder and then loop through each subfolder and call run.ps1.  This is what I presently do with CMD files, that way when I no longer need a module we just delete the folder.  Similarly if I need to add a module I just drop in a new folder.  I don&#8217;t want to edit the calling script, if I can avoid it.</p>
<p>Here&#8217;s what I have:</p>
<p>   $list = Get-ChildItem C:\APPS\SCRIPTS -exclude maintenance.ps1 | Sort-Object Name</p>
<p>   foreach ($i in $list)<br />
      {<br />
         Write-Host &#8220;Processing &#8221; $i&#8221;&#8230;&#8221;<br />
         $sScript = [STRING]$i + &#8220;\run.ps1&#8243;<br />
       # this line works<br />
         .{c:\apps\scripts00_Critical\run.ps1}<br />
       # this line doesn&#8217;t work<br />
         .{$sScript}<br />
      }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mostafa Mokhtar</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-414</link>
		<dc:creator>Mostafa Mokhtar</dc:creator>
		<pubDate>Thu, 15 Oct 2009 02:12:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-414</guid>
		<description>Hi

I wanted to know how to call powershell functions that I wrote asynchronously?
any ideas?</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>I wanted to know how to call powershell functions that I wrote asynchronously?<br />
any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Allen</title>
		<link>http://www.powershellpro.com/function-calling/144/comment-page-1/#comment-382</link>
		<dc:creator>Chris Allen</dc:creator>
		<pubDate>Fri, 24 Jul 2009 18:13:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/function-calling/144/#comment-382</guid>
		<description>Ok, I do have a question after all.

Is it possible to call a dot source file from a UNC?</description>
		<content:encoded><![CDATA[<p>Ok, I do have a question after all.</p>
<p>Is it possible to call a dot source file from a UNC?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

