很多时候,我们需要在其他工具中启动PowerShell来执行PowerShell命令,比如Cmd.exe或批处理文件。下面就来介绍下启动PowerShell的基本语法。

调用Windows PowerShell控制台基本语法:

PowerShell[.exe]
[-PSConsoleFile <file> | -Version <version>]
[-EncodedCommand <Base64EncodedCommand>]
[-ExecutionPolicy <ExecutionPolicy>]
[-File <filePath> <args>]
[-InputFormat {Text | XML}]
[-NoExit]
[-NoLogo]
[-NonInteractive]
[-NoProfile]
[-OutputFormat {Text | XML}]
[-Sta]
[-WindowStyle <style>]
[-Command { - | <script-block> [-args <arg-array>]
| <string> [<CommandParameters>] } ]

关于每个参数的含义,可以通过命令powershell -help来查看。

举例:

在一个命令提示符下或一个批处理文件中,可以用下列命令得到当前运行进程的列表:

Powershell -nologo -noprofile -command get-process

如果想使命令行执行powershell命令后保持运行不退出,可以增加-NoExit参数

Powershell -noexit -command get-process

相关文章:

  • 2021-11-01
  • 2018-01-26
  • 2021-08-16
  • 2021-05-15
  • 2021-11-13
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2021-12-27
  • 2022-02-02
  • 2021-05-14
相关资源
相似解决方案