1

I have a powershell script (test.ps1) and I want to run this from a batch file. The batch file contains the following:

PowerShell –Command “& ‘.\test.ps1’” 001
pause

When I run the batch file (as administrator) on a 32 bit Windows 7 machine, the powershell script runs successfully. When I try and run it on a 64 bit Windows 7 machine I get the following error:

C:\Windows\system32>PowerShell –Command “& ‘.\test.ps1’” 001
The term ‘.\test.ps1’ is not recognised as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if the path was included, verify that the path is correct and try again.
At line:1 char:2
+ & <<<<  ‘.\test.ps1’ 001
    + CategoryInfo              : ObjectNotFound: (.\test.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorID : CommandNotFoundException

Any ideas?

Thanks

1 Answer 1

3

You are running your script from C:\Windows\system32 and there's no such script (usually this happens when the bat is started with admin privileges ). Change the directory or call it with a full path.

The easiest way to fix this - set cd /d %~dp0 at the start of the batch script to change the directory on the location where the script is

Sign up to request clarification or add additional context in comments.

5 Comments

The test.ps1 and the batch file are in the same folder (for example C:\test).
Just checked both machines and when running the file, the 32bit machine says C:\test>... but the 64bit on starts C:\Windows\System32>.
So how do I tell the 64 bit machine to run from the folder I'm trying to run it from? (I can't put the full path in because it could be anything, the people running it can copy the files to wherever they want)
Probably you started the script with administrator priviliges - in these cases it starts from system32
set cd /d %~dp0 at the start of the batch script to change the directory on the location where the script is.

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.