3

I have this powershell script (test1.ps1) calling another powershell script(test2.ps1) to do the job.

Both scriptfiles are in the same folder

test1.ps1

echo "from test1.ps1"

.\test2.ps1

test2.ps1

echo "from test2.ps1"

When I invoke test1.ps1 in C# by creating runspace, adding commands to pipeline and invoking it, I get an error message saying "The term '.\test2.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

1
  • Please show the code you use to invoke the scripts. Commented Aug 10, 2011 at 21:04

1 Answer 1

4

Both the scripts might be in the same folder, but .\test2.ps1 will look for test2.ps1 in the same folder as the calling application, which is the C# app.

Have this in test.ps1:

$scriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
.$scriptdir\test2.ps1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.