PowerShell(包括Windows PowerShell和PowerShell Core)是微軟公司開發的任務自動化和組態管理架構,由在.NET Framework和後來的.NET上構建的命令列介面殼層相關手稿語言組成,最初僅僅是Windows元件,後於2016年8月18日開源並提供跨平台支援。[4]
Quick Facts 編程範型, 設計者 ...
Close
在PowerShell中,管理任務通常由cmdlets(發音為command-lets)執行,這是執行特定操作的專用.NET類。可以將cmdlet集合至指令碼、可執行檔(一般是獨立應用程式)中,或通過常規.NET類(或WMI / COM對象)實例化。[5][6]
UNIX系統一直有著功能強大的殼程式(shell),Windows PowerShell的誕生就是要提供功能相當於UNIX系統的命令列殼程式(例如:sh、bash或csh),同時也內建手稿語言以及輔助指令碼程式的工具。
- 一致性的設計讓所有工具和系統資料的使用語法、命名原則都相同。
- 手稿語言簡單易學,而且能支援現有的指令碼程式和命令列工具。
- 內含129種稱為cmdlet的標準工具,可用來處理常見的系統管理工作。
- 具備完整的擴充功能,獨立軟體商或開發者都能很容易的自行擴充。
- 行程間資料傳遞內容具有強型別特徵。
- PowerShell Core可以自動檢測字元編碼,自動識別Linux和Windows下的換行符,跨平台執行。
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
- 停止所有目前執行中的所有使用大於1000MB記憶體的程式:
get-process | where { $_.WS -gt 1000MB } | stop-process
get-childitem | measure-object -property length -sum
- 將"hello, world!"字串轉為英文大寫字元,成為"HELLO, WORLD!":
"hello, world!".ToUpper()
- 訂閱一個指定的RSS Feed並顯示它最近8個主題:
$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
More information PowerShell(命令列), PowerShell(別名) ...
Close
儘管外部ping命令仍可用於PowerShell,但「Test-Connection」的輸出是一個可以通過編程來檢查的結構化對象。
While the external ping command remains available to PowerShell, Test-Connection's output is a structured object that can be programmatically inspected.[7]
Clear-Host被實現為預定義的PowerShell功能。
Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
Available in Windows XP Professional Edition and later
Also used in UNIX to send a process any signal, the "Terminate" signal is merely the default
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]
- 計劃任務:可使用 Windows 任務排程程式基礎架構計劃任務在預定的時間和日期執行。
- 對談重新連接:對談可以斷開並重新連接。遠端對談現在能更好地應對臨時網路故障。
- 改進了代碼編寫:增加了代碼自動完成(IntelliSense)和代碼片段。PowerShell ISE 允許使用者使用對話方塊填寫 PowerShell cmdlet 參數。
- 授權支援:可將管理任務授權給無權執行此類任務的使用者,而無需授予他們永久性的額外權限。
- 更新幫助:可使用 Update-Help 命令更新說明文件。
WMF 3.0. www.microsoft.com. [2023-09-09]. (原始內容存檔於2023-06-19).
- Oakley, Andy. Monad (AKA PowerShell). O'Reilly Media. 2005. ISBN 0-596-10009-4.
- Holmes, Lee. Windows PowerShell Quick Reference. O'Reilly Media. 2006. ISBN 0-596-52813-2.
- Holmes, Lee. Windows PowerShell Cookbook. O'Reilly Media. 2007. ISBN 0-596-52849-3.
- Watt, Andrew. Professional Windows PowerShell. Wrox Press. 2007. ISBN 0-471-94693-1.
- Kumaravel, Arul; White, Jon; Naixin Li, Michael; Happell, Scott; Xie, Guohui; Vutukuri, Krishna C. Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers. Wrox Press. 2008. ISBN 0-470-17393-9.
- Kopczynski, Tyson; Handley, Pete; Shaw, Marco. Windows PowerShell Unleashed 2nd. Pearson Education. 2009. ISBN 978-0-672-32988-3.
- Jones, Don; Hicks, Jeffery. Windows PowerShell 2.0: TFM 3rd. Sapien Technologies. 2010. ISBN 978-0-9821314-2-8.
- Finke, Douglas. Windows PowerShell for Developers. O'Reilly Media. 2012. ISBN 1-4493-2270-0.
- Wilson, Ed. Windows PowerShell 3.0 Step by Step. Microsoft Press. 2013. ISBN 978-0-7356-6339-8.
- Wilson, Ed. Windows PowerShell Best Practices. Microsoft Press. 2014. ISBN 978-0-7356-6649-8.