Linux command
powershell 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start PowerShell
pwsh
Execute a command
pwsh -Command "[Get-Process]"
Run a script file
pwsh -File [script.ps1]
Run without profile
pwsh -NoProfile
Execute and exit
pwsh -Command "[command]" -NoExit
Run in non-interactive mode
pwsh -NonInteractive -Command "[command]"
Output in specific format
pwsh -Command "[Get-Process | ConvertTo-Json]"
Check version
pwsh -Version
说明
PowerShell (pwsh) is Microsoft's cross-platform shell and scripting language. It uses object-oriented pipelines rather than text streams, making data manipulation more structured. Commands (cmdlets) follow Verb-Noun naming: Get-Process, Set-Location, Remove-Item. Objects passed through pipelines retain properties and methods, enabling rich querying without text parsing. PowerShell integrates with .NET, providing access to its entire library. Variables are typed, parameters are named, and error handling uses try/catch/finally constructs. Profiles (~/.config/powershell/profile.ps1 on Linux) customize the environment. Functions, aliases, and variables defined in profiles persist across sessions. The language supports advanced features: classes, modules, remoting, jobs (background tasks), and workflows. It's equally capable as an interactive shell and for automation scripting.
参数
- -Command, -c _COMMAND_
- Execute specified command string.
- -File, -f _FILE_
- Run script file.
- -NoProfile, -nop
- Don't load profile scripts.
- -NoLogo, -nol
- Hide startup banner.
- -NonInteractive, -noni
- Don't prompt for input.
- -NoExit, -noe
- Don't exit after running command.
- -InputFormat _FORMAT_
- Input format: Text, XML.
- -OutputFormat _FORMAT_
- Output format: Text, XML.
- -EncodedCommand _BASE64_
- Run base64-encoded command.
- -ExecutionPolicy _POLICY_
- Set execution policy for session.
- -ConfigurationName _NAME_
- Use specific configuration.
- -WorkingDirectory _PATH_
- Set initial working directory.
- -Login, -l
- Run as login shell.
- -Version, -v
- Show version.
- -Help, -?
- Show help.
FAQ
What is the powershell command used for?
PowerShell (pwsh) is Microsoft's cross-platform shell and scripting language. It uses object-oriented pipelines rather than text streams, making data manipulation more structured. Commands (cmdlets) follow Verb-Noun naming: Get-Process, Set-Location, Remove-Item. Objects passed through pipelines retain properties and methods, enabling rich querying without text parsing. PowerShell integrates with .NET, providing access to its entire library. Variables are typed, parameters are named, and error handling uses try/catch/finally constructs. Profiles (~/.config/powershell/profile.ps1 on Linux) customize the environment. Functions, aliases, and variables defined in profiles persist across sessions. The language supports advanced features: classes, modules, remoting, jobs (background tasks), and workflows. It's equally capable as an interactive shell and for automation scripting.
How do I run a basic powershell example?
Run `pwsh` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -Command, -c _COMMAND_ do in powershell?
Execute specified command string.