系统命令

powershell 命令

powershell 是 Microsoft Learn Windows 命令参考中的命令或工具子命令。本页整理可核实的语法、参数和用法示例;适用版本、角色及运行环境请以官方来源为准。

适用版本/范围: Microsoft Learn Windows 客户端与 Windows Server 命令参考;部分条目可能属于旧版命令、服务器角色、可选功能或交互式工具子命令。English

官方文档语法

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

链接的 Microsoft Learn 文章是上游依据;命令是否可用取决于 Windows 版本、服务器角色、可选功能或交互式工具上下文。

用法示例

Microsoft Learn 官方文档示例;改用前请核对路径、目标和本机可用性。

PowerShell.exe -NoProfile

Microsoft Learn 官方文档示例;改用前请核对路径、目标和本机可用性。

PowerShell.exe -ExecutionPolicy RemoteSigned -File .\script.ps1

Microsoft Learn 官方文档示例;改用前请核对路径、目标和本机可用性。

PowerShell.exe -Command "Get-Date"

参数、选项与子句

参数 / 子句说明
-PSConsoleFile <file>加载指定的 Windows PowerShell 控制台文件。
-Version <version>在已安装时启动指定版本的 Windows PowerShell。
-NoLogo启动时隐藏版权横幅。
-NoExit启动命令执行完毕后保持 shell 打开。
-Sta / -Mta选择单线程或多线程单元模式。
-NoProfile不加载 PowerShell 配置文件。
-NonInteractive不显示交互式提示。
-InputFormat {Text|XML}选择输入数据格式。
-OutputFormat {Text|XML}选择输出数据格式。
-WindowStyle <style>设置 PowerShell 窗口样式。
-EncodedArguments <Base64EncodedArguments>传递经过 Base64 编码的命令行参数。
-EncodedCommand <Base64EncodedCommand>运行经过 Base64 编码的命令字符串。
-ConfigurationName <string>连接到指定的会话配置。
-File <filePath> <args>运行脚本文件并可传递参数;使用 - 可从标准输入读取。
-ExecutionPolicy <ExecutionPolicy>设置进程执行策略;组策略及其他范围可能具有更高优先级。
-Command <script-block|string>运行命令或脚本块后退出,除非同时指定 -NoExit。
-Help / -? / ?显示命令行帮助。
-Command - | <script-block> | <string>Microsoft Learn 列出的开关;可接受取值、影响及版本限制请查看官方来源。
/?显示命令帮助或受支持的命令行用法。
<script-block>Microsoft Learn 列出的参数或子命令;所需格式与运行上下文请查看官方来源。
-argsMicrosoft Learn 列出的开关;可接受取值、影响及版本限制请查看官方来源。
<arg-array>Microsoft Learn 列出的参数或子命令;所需格式与运行上下文请查看官方来源。
<CommandParameters>Microsoft Learn 列出的参数或子命令;所需格式与运行上下文请查看官方来源。
安全提示

执行前请核对命令和目标路径。修改文件、服务、账户、磁盘、权限或数据库的操作可能难以撤销;建议先在安全环境测试并保留备份。

参考文档 ↗返回目录