使用.bat运行PowerShell脚本时出错

使用.bat运行PowerShell脚本时出错,powershell,batch-file,Powershell,Batch File,我试图运行一个.bat文件,调用一个shell.ps1文件。 我已经在powershell中直接测试了我的脚本,它在那里工作。 但是当我运行.bat时,会出现一个错误,告诉我类似于[以:…开头的字符串不包含终止符] My.bat文件: powershell.exe -command "& C:\Users\I\Desktop\teste.ps1" My.ps1文件: $scripts = 'C:\Users\I\Desktop\Teste_0.1\Teste\Teste_run.bat

我试图运行一个.bat文件,调用一个shell.ps1文件。 我已经在powershell中直接测试了我的脚本,它在那里工作。 但是当我运行.bat时,会出现一个错误,告诉我类似于[以:…开头的字符串不包含终止符]

My.bat文件:

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

$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

要从powershell调用另一个脚本,我认为不需要使用-command。您应该能够直接调用脚本

 powershell -nol -noe C:\Users\I\Desktop\teste.ps1
或者,这里有另一个聪明的方法

@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