Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell script not firing from batch file

I've been trying to launch a simple powershell script from a batch file. After looking online the advice is to set the policy using Set-ExecutionPolicy.

I've done this and using Get-ExecutionPolicy the policy has been changed.

However running this batch file results in an 'Open With' dialog rather than the execution of the script.

Batch:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe ^&'./script.psl'

Powershell:

Write-Host "This is a message"

I have sampled on both Windows 7 and Server 2008 R2. Both have same result. What am I missing?

like image 237
Tezza Avatar asked Jun 02 '26 23:06

Tezza


1 Answers

To run a script file from the command line, use the -file parameter of powershell.exe.

 %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe  -file './script.psl'
like image 80
mjolinor Avatar answered Jun 06 '26 06:06

mjolinor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!