Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Dot sourcing multiple code files

Closed Thread
 
Thread Tools Display Modes
Old 09-30-2007   #1 (permalink)
henry Macoy
Guest


 

Dot sourcing multiple code files

Hi am new to PowerShell scripting/programming. I am trying to created a
couple of "libraries" from which code can be reused. I have created two
..ps1 files one with functions that perform some general tasks and
another that contains some variables that contain non-changing data. I a
specific script that I create I am able to dot source the file with the
functions. But when I try and another external file (the one with
variables) I loose the functionality of the first (function) file, and
cannot access the functionality from the first second file that I dot
sourced. Is there a way I can create multiple libraries that can
simultaneously be accessed by one or more scripts, with out having to
incorporate these functionality in the libraries into the Windows
PowerShell profile (config file). Let me know if you need more info to
clarify my problem and the solution I'm seeking.

Thanks
Old 10-01-2007   #2 (permalink)
Jon
Guest


 

Re: Dot sourcing multiple code files


"henry Macoy" <henry.macoy@xxxxxx> wrote in message
news:%23rDWxI%23AIHA.3780@xxxxxx
Quote:

> Hi am new to PowerShell scripting/programming. I am trying to created a
> couple of "libraries" from which code can be reused. I have created two
> .ps1 files one with functions that perform some general tasks and another
> that contains some variables that contain non-changing data. I a specific
> script that I create I am able to dot source the file with the functions.
> But when I try and another external file (the one with variables) I loose
> the functionality of the first (function) file, and cannot access the
> functionality from the first second file that I dot sourced. Is there a
> way I can create multiple libraries that can simultaneously be accessed by
> one or more scripts, with out having to incorporate these functionality in
> the libraries into the Windows PowerShell profile (config file). Let me
> know if you need more info to clarify my problem and the solution I'm
> seeking.
>
> Thanks



You can dot source more than one file within a script eg

.. "C:\Users\Me\MyFunctions.ps1"
.. "C:\Users\Me\MyVariables.ps1"

or you're perhaps encountering a scope issue

Get-Help about_Scope


Otherwise you may wish to rephrase the question.


--
Jon


Old 10-01-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: Dot sourcing multiple code files

I would recommend reading the profile that comes with PSCX. It is pretty
clear and it does exactly what you want.

"Jon" <Email_Address@xxxxxx> wrote in message
news:e2I4%23A$AIHA.1212@xxxxxx
Quote:

>
> "henry Macoy" <henry.macoy@xxxxxx> wrote in message
> news:%23rDWxI%23AIHA.3780@xxxxxx
Quote:

>> Hi am new to PowerShell scripting/programming. I am trying to created a
>> couple of "libraries" from which code can be reused. I have created two
>> .ps1 files one with functions that perform some general tasks and another
>> that contains some variables that contain non-changing data. I a specific
>> script that I create I am able to dot source the file with the functions.
>> But when I try and another external file (the one with variables) I loose
>> the functionality of the first (function) file, and cannot access the
>> functionality from the first second file that I dot sourced. Is there a
>> way I can create multiple libraries that can simultaneously be accessed
>> by one or more scripts, with out having to incorporate these
>> functionality in the libraries into the Windows PowerShell profile
>> (config file). Let me know if you need more info to clarify my problem
>> and the solution I'm seeking.
>>
>> Thanks
>
>
>
>
> You can dot source more than one file within a script eg
>
> . "C:\Users\Me\MyFunctions.ps1"
> . "C:\Users\Me\MyVariables.ps1"
>
> or you're perhaps encountering a scope issue
>
> Get-Help about_Scope
>
>
> Otherwise you may wish to rephrase the question.
>
>
> --
> Jon
>
>
Old 10-01-2007   #4 (permalink)
Hal Rottenberg
Guest


 

Re: Dot sourcing multiple code files

henry Macoy wrote:
Quote:

> sourced. Is there a way I can create multiple libraries that can
> simultaneously be accessed by one or more scripts, with out having to
> incorporate these functionality in the libraries into the Windows
> PowerShell profile (config file). Let me know if you need more info to
> clarify my problem and the solution I'm seeking.
There is no reason this should not work, so I'd say we need more info to see
what's going wrong in your case.

--

Hal Rottenberg
Blog: http://halr9000.com
Webmaster, Psi (http://psi-im.org)
Co-host, PowerScripting Podcast (http://powerscripting.net)
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple .snk files Greyhound .NET General 1 07-09-2008 08:08 PM
Possible to Read only Selected lines from multiple files into anotherfile deleting source files when processed? joe.hurzeler PowerShell 3 03-09-2008 10:03 PM
does .dot-sourcing a set of functions compile these into MSIL? Bob Landau PowerShell 4 10-09-2007 03:05 PM
Vista Code = Multiple Problems ByeByeBirdie Vista General 6 10-05-2007 09:43 PM
sourcing a file in a script JasonM PowerShell 5 08-31-2007 03:22 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50