![]() | |
![]() 在Windows Terminal内运行的PowerShell 7 | |
编程范型 | 命令式、管道、面向对象、函数式、反射式 |
---|---|
設計者 | 杰弗里·史诺威(Jeffrey Snover) 布鲁斯·帕耶特(Bruce Payette) 詹姆斯·特鲁赫(James Truher) (et al.) |
實作者 | Microsoft |
发行时间 | 2006年11月14日 |
当前版本 |
|
型態系統 | 强类型、类型安全、类型推论和动态类型 |
系统平台 | PowerShell: .NET Windows PowerShell: .NET框架 |
操作系统 | Windows 7及其后续版本、Linux、macOS |
許可證 | MIT許可證[2](但Windows组件仍然是专有的) |
文件扩展名 |
|
網站 | microsoft |
啟發語言 | |
Ksh、Perl、C#、CL、DCL、SQL、Tcl、Tk、[3]Chef、Puppet |
PowerShell(包括Windows PowerShell和PowerShell Core)是微軟公司开发的任务自动化和組態管理架構,由在.NET Framework和后来的.NET上构建的命令行界面殼層相关脚本语言组成,最初僅僅是Windows元件,后于2016年8月18日开源并提供跨平台支持。[4]
在PowerShell中,管理任务通常由cmdlets(发音为command-lets)执行,这是执行特定操作的专用.NET类。可以将cmdlet集合至脚本、可执行文件(一般是独立应用程序)中,或通过常规.NET类(或WMI / COM对象)实例化。[5][6]
UNIX系統一直有著功能強大的殼程式(shell),Windows PowerShell的誕生就是要提供功能相當於UNIX系統的命令列殼程式(例如:sh、bash或csh),同時也內建腳本語言以及輔助腳本程式的工具。
cmdlet是Windows PowerShell的指令,發音唸法為command-let。這相當於DOS或其他殼程式的內建指令,指令名稱的格式都是以連字號(-)隔開的一對動詞和名詞,並且通常都是單數名詞;例如線上查詢說明的cmdlet指令為get-help,名稱的動詞部分大致有get、set、add、remove等等(字母都不分大小寫)。
Windows PowerShell ISE是Windows PowerShell的主机应用程序。在此程序中,可以在单个Windows GUI中运行命令、编辑与测试脚本。此程序具有多行编辑、Tab补齐、上下文相关帮助、语法着色、选择性执行等功能,而且还支持从右到左的书写顺序等功能。
Windows PowerShell是以.NET Framework技術為基礎,並且與現有的WSH保持回溯相容,因此它的腳本程式不僅能存取.NET CLR,也能使用現有的COM技術。同時也包含了數種系統管理工具、簡易且一致的語法,常見如登錄資料庫、WMI。Exchange Server 2007以及System Center Operations Manager 2007等伺服器軟體都將內建Windows PowerShell。
get-process p* | stop-process
get-process | where { $_.WS -gt 1000MB } | stop-process
get-childitem | measure-object -property length -sum
"hello, world!".ToUpper()
$rssUrl = "http://blogs.msdn.com/powershell/rss.aspx"
$blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
$blog.rss.channel.item | select title -first 8
PowerShell(命令行) | PowerShell(別名) | 命令提示符 | Unix shell | 描述 |
---|---|---|---|---|
Get-ChildItem | gci, dir, ls | dir | ls | 列出目前或指定資料夾中的所有檔案和資料夾 |
Test-Connection[a] | ping | ping | ping | 從目前電腦向指定電腦傳送Ping,或指示另一台電腦這樣做 |
Get-Content | gc, type, cat | type | cat | 取得檔案內容 |
Get-Command | gcm | help | type, which, compgen | 列出可用的命令 |
Get-Help | help, man | help | apropos, man | 在控制台上打印命令的文档 |
Clear-Host | cls, clear | cls | clear | 清除屏幕[b] |
Copy-Item | cpi, copy, cp | copy, xcopy, robocopy | cp | 將檔案和資料夾複製到另一個位置 |
Move-Item | mi, move, mv | move | mv | 將檔案和資料夾移動到新位置 |
Remove-Item | ri, del, erase, rmdir, rd, rm | del, erase, rmdir, rd | rm, rmdir | 刪除檔案或資料夾 |
Rename-Item | rni, ren, mv | ren, rename | mv | 重命名單個檔案、資料夾、硬連結或符號連結 |
Get-Location | gl, cd, pwd | cd | pwd | 顯示工作路徑(目前資料夾) |
Pop-Location | popd | popd | popd | 將工作路徑更改為最近推送到堆疊上的位置 |
Push-Location | pushd | pushd | pushd | 將工作路徑儲存到堆疊中 |
Set-Location | sl, cd, chdir | cd, chdir | cd | 改變工作路徑 |
Tee-Object | tee | 不適用 | tee | 將輸入管道傳輸到檔案或變數,並沿管道傳遞輸入 |
Write-Output | echo, write | echo | echo | 將字符串或其他對像打印到標準串流 |
Get-Process | gps, ps | tlist,[c] tasklist[d] | ps | 列出所有正在執行的處理程序 |
Stop-Process | spps, kill | kill,[c] taskkill[d] | kill[e] | 停止正在執行的處理程序 |
Select-String | sls | findstr | find, grep | 打印与模式匹配的行 |
Set-Variable | sv, set | set | env, export, set, setenv | 创建或更改环境变量的內容 |
Invoke-WebRequest | iwr, |
curl | wget, curl | 取得互联网上的网页內容 |
curl
and wget
aliases are absent from PowerShell Core, so as to not interfere with invoking similarly named native commands.
PowerShell 3.0 与 Windows 8 和 Windows Server 2012 集成。微软还为 Windows 7 的 Service Pack 1、Windows Server 2008 的 Service Pack 1 和 Windows Server 2008 R2 的 Service Pack 1 提供了 PowerShell 3.0。[8][9]
PowerShell 3.0 是一个更大的软件包 Windows Management Framework 3.0 (WMF3) (WMF3) 的一部分。 PowerShell 3.0 是一个更大的软件包 Windows 管理框架 3.0 (WMF3) 的一部分,其中还包含支持远程协作的 WinRM 服务。[10][11]
PowerShell 3.0 的新功能包括:[12][13]
|
|
|
|
|