https://learn.microsoft.com/zh-cn/powershell/
概述
https://learn.microsoft.com/zh-cn/powershell/scripting/overview
https://learn.microsoft.com/zh-cn/powershell/scripting/what-is-windows-powershell
这里区分 PowerShell 和 Windows PowerShell。
https://learn.microsoft.com/zh-cn/powershell/scripting/powershell-commands
cmdlet,即 PowerShell 命令,使用动词-名词对来命名。
安装
https://learn.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows
安装之后,和旧版 Windows PowerShell 两者并存。之后比如在 VS Code 打开的终端,就会默认为这个新的 PowerShell 了。
了解 PowerShell
优化 shell 体验
https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/optimize-shell
使用 Tab 自动补全
https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/tab-completion
使用命令预测器
https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/using-predictors
使用别名
https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/using-aliases
自定义 shell 环境
https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/creating-profiles
参考
Microsoft.PowerShell.Core
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/
关于
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about
about_Aliases
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_aliases
命令的别名。
1 | Get-Command -Noun Alias |
显示用于管理别名的 cmdlet。
about_Automatic_Variables
关于 PowerShell 中的自动变量。
about_Environment_Variables
关于环境变量。
1 | Get-ChildItem Env: |
1 | $Env:windir |
about_Pipelines
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_pipelines
about_Pipeline_Chain_Operators
可以使用&&
和||
运算符了,这就非常方便。
about_Profiles
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_profiles
关于 PowerShell 配置文件。
Clear-Host
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/clear-host
清除显示内容,清空终端屏幕。
常用的别名是clear
。
Get-Command
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/get-command
用于获取命令。
一个用途是查看命令的位置。
1 | Get-Command python |
Import-Module
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/import-module
用于将模块添加到当前会话。
Microsoft.PowerShell.Management
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/
Copy-Item
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/copy-item
复制文件。
常用的别名是cp
。
Get-ChildItem
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-childitem
获取指定文件路径位置中的子项。
常用的别名是ls
。
Get-Content
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content
获取文件内容。主要是文本文件。
-TotalCount
参数,从文件的开头获取指定行数的内容。
常用的别名是cat
。
Get-Item
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-item
获取文件和文件夹的属性。
New-Item
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/new-item
用于新建文件。
-ItemType
参数,指定新建的项的类型,比如File
和Directory
。
Remove-Item
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/remove-item
用于删除文件和文件夹。
常用的别名有rm
和rmdir
。
Rename-Item
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/rename-item
重命名文件和文件夹。
Stop-Process
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/stop-process
停止进程。
-Id
参数用于指定进程的 ID。-Name
参数用于指定进程的名称。
Test-Path
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/test-path
用于确定路径是否存在。
Microsoft.PowerShell.Security
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.security/
Get-ExecutionPolicy
Set-ExecutionPolicy
Microsoft.PowerShell.Utility
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/
Get-Culture
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/get-culture
Get-Date
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/get-date
Write-Host
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/write-host
Write-Output
https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.utility/write-output
相比Write-Host
,Write-Output
会将对象发送到管道。
PSReadLine
https://learn.microsoft.com/zh-cn/powershell/module/psreadline/
说些什么吧!