<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx</link><description>A lot of the time, I want to build scripts that depend on other scripts that I’ve already written. Sometimes I will just want to be able to use a custom Cmdlet or function I’ve written. Sometimes, I’ll simply want to always call the underlying script</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Scripting Games 2008 Beginners Windows PowerShell Events 3 + 4</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#7896409</link><pubDate>Tue, 26 Feb 2008 00:24:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7896409</guid><dc:creator>The PowerShell Guy</dc:creator><description>&lt;p&gt;And I almost forgot the beginners events, not much special here : Event 3 d ir c:\scripts\*.txt |% {(get-content&lt;/p&gt;
</description></item><item><title>re: How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#7923186</link><pubDate>Thu, 28 Feb 2008 01:16:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7923186</guid><dc:creator>Dan</dc:creator><description>&lt;p&gt;Thanks for writing this. &amp;nbsp;I am trying to understand what you are saying. &amp;nbsp;So first I want to understand the problem you are trying to solve. &amp;nbsp;Is it that you can't run scripts in the current directory without an explicit path?&lt;/p&gt;
&lt;p&gt;Shouldn't you have a directory for your scripts? &amp;nbsp;And shouldn't that directory be on the path? &amp;nbsp;Wouldn't that fix this?&lt;/p&gt;</description></item><item><title>re: How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#8010704</link><pubDate>Tue, 04 Mar 2008 00:53:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8010704</guid><dc:creator>PowerShellTeam</dc:creator><description>&lt;p&gt;The problem I am trying to solve is how to write your scripts in a way that they can work well in relative paths. &amp;nbsp;I do have a script directory, but I also have many subdirectories beneath this directory. &amp;nbsp;I do not want each script that I write to be fully self contained, because I will have to write more code and because copying/pasting code will inevitably lead to differences as the code in the original files changes.&lt;/p&gt;
</description></item><item><title>re: How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#8053448</link><pubDate>Wed, 05 Mar 2008 20:36:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8053448</guid><dc:creator>Clint Bergman</dc:creator><description>&lt;p&gt;I have been struggling with this as well, and came up with a similar approach. &amp;nbsp;Part of my trouble is that I have multiple subdirectoies beneath my root scripts directory. &amp;nbsp;So I wrote a function that will locate script/binary dependencies and throws terminating errors if it cannot find those specified:&lt;/p&gt;
&lt;p&gt;function Get-ResourcePath {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;param(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[string]$filename = $(Throw '-filename must be specified!'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[string]$srchPath = $(Split-Path $MyInvocation.Scriptname),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[int]$srchUp = 0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;$fileNotFound = $true&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;for ( $i = $srchUp ; $i -gt -1 ; $i-- ) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$Result = @(Get-ChildItem $srchPath $filename -recurse)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ($Result[0] -ne $null) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Write-Host &amp;quot;Necessary resource $filename found at $($Result[0].fullname)&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#Return the full path to the file being searched for.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@($Result)[0].fullname&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$fileNotFound = $false&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$srchPath = Split-Path $srchPath&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if ($fileNotFound) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Throw &amp;quot;Necessary Resource: $Filename not Found!&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;For production scripts I have defined the root in the global profile as $PSDAdminscriptroot and root my searches for dependencies there.&lt;/p&gt;
&lt;p&gt;I'm always looking to improve the way I search for dependencies, any comments/ideas on my searching script are appreciated.&lt;/p&gt;
&lt;p&gt;Thanks for posting your solution, adding aliases is something I'll have to incorporate into our scripts here.&lt;/p&gt;</description></item><item><title>re: How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#8206654</link><pubDate>Fri, 14 Mar 2008 20:08:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8206654</guid><dc:creator>Jason Archer</dc:creator><description>&lt;p&gt;What are the differences between interdependent scripts versus implementing your logic in functions and scripted cmdlets, and then kick starting things with scripts?&lt;/p&gt;</description></item><item><title>re: How to Write Interdependent Scripts</title><link>http://blogs.msdn.com/powershell/archive/2008/02/22/how-to-write-interdependent-scripts.aspx#8510959</link><pubDate>Fri, 16 May 2008 07:12:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8510959</guid><dc:creator>Tin</dc:creator><description>&lt;p&gt;Note to self:&lt;/p&gt;
&lt;p&gt;See if this have anything to do with &amp;quot;dotting&amp;quot; a script as described in &amp;quot;Windows PowerShell in Action&amp;quot;, chapter 7, page 210.&lt;/p&gt;
&lt;p&gt;script1.ps1&lt;/p&gt;
&lt;p&gt;--------------&lt;/p&gt;
&lt;p&gt;function doit($what)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; write-host &amp;quot;done $what&amp;quot;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;--------------&lt;/p&gt;
&lt;p&gt;script2.ps1&lt;/p&gt;
&lt;p&gt;--------------&lt;/p&gt;
&lt;p&gt;# call script1 to create the function&lt;/p&gt;
&lt;p&gt;(dir function:/).Count&lt;/p&gt;
&lt;p&gt;. './script1.ps1'&lt;/p&gt;
&lt;p&gt;(dir function:/).Count&lt;/p&gt;
&lt;p&gt;#now use it&lt;/p&gt;
&lt;p&gt;doit 'whatever'&lt;/p&gt;
&lt;p&gt;--------------&lt;/p&gt;</description></item></channel></rss>