TimCross
TimCross

Reputation: 101

Running PowerShell script from a batch file successful on 32 bit but fails on 64 bit

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

Upvotes: 1

Views: 2354

Answers (1)

npocmaka
npocmaka

Reputation: 57262

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

Upvotes: 3

Related Questions