Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

defect in powershell w/ running script that references another script

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
i have a powershell script that loads other powershell scripts. when i run this script in a powershell session, it runs fine. however, if i run it from a standard command window, any functions defined in the secondary powershell scripts are no longer recognized!? anyone familiar with this problem and how to get things working?

for example:

main powershell script: main.ps1
Code:
& '.\test1.ps1'

cls;
function1;

include file: test1.ps1
Code:
function global:function1()
{
    write-host "in function 1";
}

then, from a standard command window (the idea is that a batch file will be launching this), i run...

Code:
powershell -command "& {main.ps1}"

at this point, it will display an error that term "function1" is not recognized. however, if i open a powershell session and run...

Code:
.\main.ps1

it runs fine. any suggestions?

glenn
 
oops. just realized my problem. i was launching powershell from the powershell directory and specifying the absolute path to the main script. but the include files are referenced by relative path and consequently were not being loaded (no errors returned on that). powershell is in my environment path, so by launching powershell from the directory containing the scripts, everything ran as expected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top