我想在没有蓝屏的情况下静默执行PowerShell命令。
如何从PowerShell命令执行此操作?
我试过这个。. .
PowerShell.exe -windowstyle hidden
Run Code Online (Sandbox Code Playgroud)
但它不起作用 - 命令已执行但蓝屏仍然存在。
就像声明的那样。. .
"您可以使用 PowerShell.exe 从其他工具的命令行启动 PowerShell 会话,例如 Cmd.exe,或在 PowerShell 命令行中使用它启动新会话。使用参数自定义会话。 "
-WindowStyle
设置会话的窗口样式。有效值为正常、最小化、最大化和隐藏。
-命令
执行指定的命令(和任何参数),就像在 PowerShell 命令提示符下键入它们一样,然后退出,除非指定了 NoExit 参数。本质上,之后的任何文本
-Command都作为单个命令行发送到 PowerShell
句法
Run Code Online (Sandbox Code Playgroud)powershell -windowstyle hidden -command <PowerShell Command String>
1.命令提示符(cmd)
Run Code Online (Sandbox Code Playgroud)powershell -windowstyle hidden -command get-childitem -path c:\ ^| out-file "C:\Folder\Log\log.txt"注意: 使用 cmd 时,[
|] 管道符号需要使用 [^] 插入符号进行转义,因此“^|”。
2. PowerShell 提示
Run Code Online (Sandbox Code Playgroud)powershell -windowstyle hidden -command get-childitem -path c:\ | out-file "C:\Folder\Log\log.txt"注意: 运行后,打开log.txt以验证其内容,因为
out-file它会直接输出。
| 归档时间: |
|
| 查看次数: |
66412 次 |
| 最近记录: |