如何通过其他工具的命令行启动PowerShell

很多时候,我们需要在其他工具中启动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

原文地址:https://www.cnblogs.com/ITGirlXiaoXiao/p/2620036.html