Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Dot sourcing multiple code files

Reply
 
Old 10-01-2007   #1 (permalink)
henry Macoy


 
 

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

My System SpecsSystem Spec
Old 10-01-2007   #2 (permalink)
Jon


 
 

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


My System SpecsSystem Spec
Old 10-01-2007   #3 (permalink)
Brandon Shell


 
 

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
>
>
My System SpecsSystem Spec
Old 10-01-2007   #4 (permalink)
Hal Rottenberg


 
 

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)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Dot-sourcing and scope PowerShell
Newbie question: replace multiple strings in multiple text files VB Script
does .dot-sourcing a set of functions compile these into MSIL? PowerShell
Vista Code = Multiple Problems Vista General
sourcing a file in a script PowerShell


Vista Forums 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 Ltd

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