Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm trying to run a .bat file calling a shell .ps1 file. I've tested my script directly in powershell and there it works. But when I run the .bat, a error occurs saying to me something like [ The string started with: (...) does not contain the terminator " ]

My .bat file:

powershell.exe -command "& C:\Users\I\Desktop\teste.ps1"

My .ps1 file:

$scripts = 'C:\Users\I\Desktop\Teste_0.1\Teste\Teste_run.bat', 'C:\Users\I\Desktop\Teste_0.2\Teste\Teste_run.bat','C:\Users\I\Desktop\Teste_0.3\Teste\Teste_run.bat' |%{ Start-Job –scriptblock (iex "[Scriptblock] { $_ } ")}| wait-job
share|improve this question

1 Answer 1

To call another script from powershell, I don't think you need to use -command. You should just be able to call the script directly.

 powershell -nol -noe C:\Users\I\Desktop\teste.ps1

Alternately, here is another clever way to do it.

@echo off
  more +4 "%~dpnx0" >> temp.ps1 && powershell -nol -noe .\temp.ps1
exit /b

$scripts = 'C:\Users\I\Desktop\Teste_0.1\Teste\Teste_run.bat', 'C:\Users\I\Desktop\Teste_0.2\Teste\Teste_run.bat','C:\Users\I\Desktop\Teste_0.3\Teste\Teste_run.bat' |%{ Start-Job –scriptblock (iex "[Scriptblock] { $_ } ")}| wait-job
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.