您必须在“-”运算符之后提供值表达式

Yah*_* -_ 4 powershell expression cmd

我在 PowerShell 中有一些代码,我需要在 cmd.exe 中使用它

我在 cmd.exe 中使用这个命令

powershell -command "command"
Run Code Online (Sandbox Code Playgroud)

但它给了我这个错误

powershell -command "command"
Run Code Online (Sandbox Code Playgroud)

我的命令是:

powershell -command "(Get-Content D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace "REG_SZ", " "} | Foreach-object {$_ -replace "Gmail", " "} | set-content D:\15.txt"
Run Code Online (Sandbox Code Playgroud)

Fro*_* F. 6

您不能使用双引号来包装命令和命令本身。Cmd.exe/Powershell.exe"REG_SZ"在本例中的下一个双引号处结束命令。尝试在命令中使用单引号:

powershell -command "(Get-Content D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace 'REG_SZ', ' '} | Foreach-object {$_ -replace 'Gmail', ' '} | set-content D:\15.txt"
Run Code Online (Sandbox Code Playgroud)