Windows PowerShell

Multi tool use
Multi tool use






























































PowerShell

PowerShell 5.0 icon.png

Windows PowerShell 1.0 PD.png
Screenshot of a Windows PowerShell session

编程范型
命令式、Pipeline英语Pipeline (software)、面向对象、函数式、反射式
設計者
杰弗里·史诺威英语Jeffrey Snover(Jeffrey Snover)
布鲁斯·帕耶特(Bruce Payette)
詹姆斯·特鲁赫(James Truher) (et al.)
實作者
Microsoft
发行时间
2006年11月14日,​12年前​(2006-11-14

穩定版本
5.1.17763.55
(2018年10月10日,​39天前​(2018-10-10


預覽版本
6.2.0-preview.1
(2018年10月15日,​34天前​(2018-10-15


型態系統
强类型、类型安全、类型推论和动态类型
系统平台
.NET Framework, .NET Core
作業系統
Windows 7及其后续版本、macOS、CentOS、Ubuntu
許可證
MIT許可證[1](但Windows组件仍然是专有的)
文件扩展名


  • .ps1 (脚本文件)

  • .ps1xml(XML文档)

  • .psc1(控制台文件)

  • .psd1(数据文件)

  • .psm1(脚本模块)

  • .pssc(会话配置文件)

  • .cdxml (Cmdlet定义的XML文档)



網站
microsoft.com/powershell
啟發語言

Ksh、Perl、C#、CL英语IBM i Control LanguageDCL英语DIGITAL Command Language、SQL、Tcl、Tk、[2]Chef、Puppet英语Puppet (software)

PowerShell(包括Windows PowerShell and PowerShell Core)是微軟公司开发的任务自动化和組態管理框架,由.NET Framework和.NET Core是构建的命令行界面殼層相关脚本语言组成,最初仅Windows组件,后于2016年8月18日开源并跨平台支持。[3]


在PowerShell中,管理任务通常由cmdlets(发音为command-lets)执行,这是执行特定操作的专用.NET类。可以将cmdlet集合至脚本、可执行文件(一般是独立应用程序)中,或通过常规.NET类(或WMI / COM对象)实例化。[4][5]通过访问不同数据存储中的数据由PowerShell运行,如资源管理器或注册表。




目录






  • 1 源起與目的


  • 2 程式特性


  • 3 技術基礎


  • 4 範例


  • 5 參考文獻


  • 6 擴展閱讀


  • 7 外部連結





源起與目的


UNIX系統一直有著功能強大的殼程式(shell),Windows PowerShell的誕生就是要提供功能相當於UNIX系統的命令列殼程式(例如:sh、bash或csh),同時也內建腳本語言以及輔助腳本程式的工具。



程式特性



  • 一致性的設計讓所有工具和系統資料的使用語法、命名原則都相同。

  • 腳本語言簡單易學,而且能支援現有的腳本程式和命令列工具。

  • 內含129種稱為cmdlet的標準工具,可用來處理常見的系統管理工作。

  • 具備完整的擴充功能,獨立軟體商或開發者都能很容易的自行擴充。

  • 进程间数据传递内容具有强类型特征。


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。



範例


  • 获取所有命令[6]

PS> Get-Command

  • 查看Get-Command命令的用法[7]

PS> Get-Help Get-Command

  • 停止所有目前執行中的以"p"字元開頭命名的程式:

PS> get-process p* | stop-process

  • 停止所有目前執行中的所有使用大於1000MB記憶體的程式:

PS> get-process | where { $_.WS -gt 1000MB } | stop-process

  • 計算一個目錄下檔案內的位元組大小:

PS> get-childitem | measure-object -property length -sum

  • 等待一個叫做"notepad"的程式執行結束:

PS> $processToWatch = get-process notepad
PS> $processToWatch.WaitForExit()

  • 將"hello, world!"字串轉為英文大寫字元,成為"HELLO, WORLD!":

PS> "hello, world!".ToUpper()

  • 在字串"string"的第1個字元後插入字串"ABC",成為"sABCtring":

PS> "string".Insert(1, "ABC")

  • 訂閱一個指定的RSS Feed並顯示它最近8個主題:

PS> $rssUrl = "http://blogs.msdn.com/powershell/rss.aspx"
PS> $blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
PS> $blog.rss.channel.item | select title -first 8

  • 把"$UserProfile"設定成數值"UserProfile"的環境變數:

PS> $UserProfile = $env:UserProfile


參考文獻





  1. ^ PowerShell LICENSE


  2. ^ Snover, Jeffrey. PowerShell and WPF: WTF. Windows PowerShell Blog. Microsoft. 2008-05-25. 


  3. ^ Bright, Peter. PowerShell is Microsoft's latest open source release, coming to Linux, OS X. Ars Technica. Condé Nast. 2016-08-18. 


  4. ^ How Windows PowerShell works. Microsoft Developer Network. Microsoft. [2007-11-27]. 


  5. ^ Truher, Jim. Extend Windows PowerShell With Custom Commands. MSDN Magazine (Microsoft). December 2007. (原始内容存档于6 October 2008). 


  6. ^ Get-Command. Microsoft TechNet. 2012-08-15 [2013-07-19]. 


  7. ^ Get-Help. Microsoft TechNet. 2012-10-30 [2013-07-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英语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英语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. 



外部連結


微软官网



  • Windows PowerShell[永久失效連結]:PowerShell简介


  • Windows PowerShell 3.0 Core Modules[永久失效連結]PowerShell 3.0核心模块及模块中的命令用法


  • Windows PowerShell Reference[永久失效連結]


  • 使用 Windows PowerShell 撰寫指令碼[永久失效連結]

  • 易學易用的Windows PowerShell

  • PowerShell源代码

  • MSDN视频教程


其他



  • GitHub上的PowerShell頁面


  • TechNet維基:Windows PowerShell Survival Guide













l5z8vji bq5L8ocvbJa5Ec,gqfW9b 7LZ2 xNzzx foe,AfL Ip04coHuG4IcHpl
S5,I3j,QVPZQnKfOLKWBXxn PGzCxeAbz92XYnIKeJT37T,UUgAiRp hM

Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

Guess what letter conforming each word

Run scheduled task as local user group (not BUILTIN)