我正在尝试创建一个bacth文件,该文件将创建另一个bacth文件并将其内容设置为此:
powershell关闭/ s / f / t 0
我要使用的命令是 powershell设置内容“ shutdown.bat”“ powershell关闭/ s / f / t 0”
当我运行它时,我得到这个:
Set-Content : A positional parameter cannot be found that accepts argument 'shutdown'.
At line:1 char:1
+ set-content -Path shutdown.bat -Value powershell shutdown /s /f /t 0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
答案 0 :(得分:0)
这个...
powershell shutdown /s /f /t 0
...不是使用Powershell运行外部命令行工具或其他程序的方法。要运行外部工具,这是有据可查的/谈论的东西...
PowerShell: Running Executables
Solve Problems with External Command Lines in PowerShell
Top 5 tips for running external commands in Powershell
Using Windows PowerShell to run old command-line tools (and their weirdest parameters)
...以及相当日常的活动。
进行后续操作时,必须使用正确的引号和引号终止。
所以,像这样的东西...
powershell -ArgumentList '-Command &{ shutdown /s /f /t 0 }'