Powershell 制作批处理文件时遇到问题

Powershell 制作批处理文件时遇到问题,powershell,batch-file,Powershell,Batch File,我正在尝试生成一个bacth文件,该文件将生成第二个bacth文件,并将其内容设置为: powershell关闭/s/f/t 0 我尝试使用的命令是 powershell设置内容“shutdown.bat”“powershell shutdown/s/f/t 0” 当我运行它时,我得到以下信息: Set-Content : A positional parameter cannot be found that accepts argument 'shutdown'. At line:1 char

我正在尝试生成一个bacth文件,该文件将生成第二个bacth文件,并将其内容设置为:

powershell关闭/s/f/t 0

我尝试使用的命令是 powershell设置内容“shutdown.bat”“powershell shutdown/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
这个

powershell shutdown /s /f /t 0
。。。不是使用Powershell运行外部命令行工具或其他程序的方法。要运行外部工具,这是一个有很好文档记录/讨论的问题

。。。以及相当日常的活动

当你在做你想做的事情时,正确的引用和论点终止是一项要求

所以,像这样的东西

powershell -ArgumentList '-Command  &{ shutdown /s /f /t 0 }'

不要创建与正在运行的命令同名的脚本。Get-Help设置内容-示例也请尝试
shutdown/?
,因为在未提供
/D
选项的情况下,不应使用
shutdown.exe
。它很可能是
/D P:4:1
,因为没有计划的恶意行为的原因码。此外,您不应该将
0
/t
结合使用,并将其与
/F
选项结合使用,除非您试图破坏某些东西!使用批处理文件创建另一个批处理文件以运行PowerShell以运行外部命令行工具毫无意义。您实际上是在调用cmd.exe 3次以运行命令。