Reputation: 281
I have 2 powershell scripts one processes low level xmfiles, the other reads in a top level xml file, pulls out ID values from it and then tries to call the low level xml file processing script, passing in the ID. I developed the low level file first using a hard coded ID and it all now works fine. I added param($ID) at the very top of the called file. I then tried to call the file from the parent xml script thus:
./ChildXmlFile.ps1 "xyz"
This gives me an error:
./ChildXmlFile.ps1 is not recognized as the name of a cmdlet, function, script file, or operable program.
I tried forward slash, back slash, with and without '.ps1' on the end, same result every time.
Is there a way of calling the script from the parent? They both reside in the same directory on disk. My working directory if you like.
Many thanks
Upvotes: 1
Views: 325
Reputation: 22847
Powershell scripts don't inherit the directories of their parents when they are called for some reason - not doubt a security "feature". They start in the home directory of the user. I ran into this a couple of weeks ago and fixed it by passing the directory as an argument and doing a "cd" to that directory. I know this is a terrible hack, still looking for a good way to do it.
Upvotes: 0
Reputation: 10001
You can dot source a script like this:
. .\ChildXmlFile.ps1 "xyz"
Upvotes: 1