PowerShell:修订间差异

删除的内容 添加的内容
命令提示字元比较:​ 調整內部連結
 
(未显示15个用户的38个中间版本)
第1行:
{{Expand English|PowerShell|time=2021-08-16T21:56:27+00:00}}
{{noteTA
|G1=IT
第5行 ⟶ 第6行:
{{Infobox programming language
| name = PowerShell
| logo = PowerShell 5Core 6.0 icon.png
| screenshot = Windows PowerShell Core 7.1.05 with Windows PDTerminal.png
| screenshot caption = Screenshot of a 在[[Windows Terminal]]内运行的PowerShell session7
| paradigm = [[指令式編程|命令式]]、[[管道 (软件)|管道]]、[[面向对象程序设计|面向对象]]、[[函数编程语言|函数式]]、[[反射 (计算机科学)式编程|反射式]]
| released = {{start date and age|2006|11|14}}
| designer = {{link-en|杰弗里·史诺威|Jeffrey Snover}}(Jeffrey Snover)<br/>布鲁斯·帕耶特(Bruce Payette)<br/>詹姆斯·特鲁赫(James Truher) (et al.)
| developer = [[微软|Microsoft]]
| latest release version = 7.0.3 {{LSR/wikidata}}
| latest release date = {{start date and age|2020|07|16}}
| latest preview version =
| latest preview date =
第19行 ⟶ 第20行:
| dialects =
| influenced =
| platform = PowerShell: [[.NET框架|.NET Framework]],<br />Windows PowerShell: [[.NET Core框架]]
| license = [[MIT許可證]]<ref>[{{Cite web |url=https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt |title=PowerShell LICENSE] |access-date=2017-06-10 |archive-date=2022-05-11 |archive-url=https://web.archive.org/web/20220511115840/https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt }}</ref>(但Windows组件仍然是[[专有软件|专有的]])
| influenced_by = [[KornShell|Ksh]]、[[Perl]]、{{tsl|en|C♯||C#}}、{{link-en|IBM i 控制语言|IBM i Control Language|CL}}、{{link-en|DIGITAL命令语言|DIGITAL Command Language|DCL}}、[[SQL]]、[[Tcl]]、[[Tk]]、<ref name="snover2008">{{cite web|last = Snover|first = Jeffrey|title = PowerShell and WPF: WTF|date = 2008-05-25|url = https://blogs.msdn.microsoft.com/powershell/2008/05/25/powershell-and-wpf-wtf/|website = Windows PowerShell Blog|publisher = Microsoft|access-date = 2017-06-10|archive-date = 2019-01-08|archive-url = https://web.archive.org/web/20190108162204/https://blogs.msdn.microsoft.com/powershell/2008/05/25/powershell-and-wpf-wtf/}}</ref>{{tsl|en|Chef||Chef}}、{{link-en|[[Puppet|Puppet (software)}}]]
| operating_system = [[Windows 7]]及其后续版本、[[Linux]]、[[macOS]]
| genre = [[殼層]]、[[組態管理]]
第35行 ⟶ 第36行:
}}
 
'''PowerShell'''(包括'''Windows PowerShell'''和'''PowerShell Core''')是[[微軟公司]]开发的任务自动化和[[組態管理]],由[[.NET框架|.NET Framework]]和后来的[[.NET Core]]构建的[[命令行界面]][[殼層]]相关脚本语言组成,最初僅僅是[[Windows]]元件,后于2016年8月18日[[开放源代码|开源]]并提供[[跨平台]]支持。<ref name=ars-opensource>{{cite web|last1=Bright|first1=Peter|title=PowerShell is Microsoft's latest open source release, coming to Linux, OS X|url=http://arstechnica.com/information-technology/2016/08/powershell-is-microsofts-latest-open-source-release-coming-to-linux-os-x/|website=[[Ars Technica]]|publisher=[[康泰纳仕|Condé Nast]]|date=2016-08-18|access-date=2017-06-10|archive-date=2022-04-28|archive-url=https://web.archive.org/web/20220428143534/https://arstechnica.com/information-technology/2016/08/powershell-is-microsofts-latest-open-source-release-coming-to-linux-os-x/}}</ref>
 
在PowerShell中,管理任务通常由cmdlets(发音为command-lets)执行,这是执行特定操作的专用.NET[[类 (计算机科学)|类]]。可以将cmdlet集合至脚本、可执行文件(一般是独立应用程序)中,或通过常规.NET类(或WMI / COM对象)实例化。<ref name="how">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714658.aspx | title = How Windows PowerShell works | website = [[Microsoft Developer Network]] | publisher = [[微软|Microsoft]] | accessdate = 2007-11-27 | archive-date = 2008-09-05 | archive-url = https://web.archive.org/web/20080905054903/http://msdn2.microsoft.com/en-us/library/ms714658.aspx }}</ref><ref name="MSDN">{{cite magazine | last=Truher | first=Jim | date=December 2007 | url = https://msdn.microsoft.com/en-us/magazine/cc163293.aspx | title = Extend Windows PowerShell With Custom Commands | work = [[微软开发者网络|MSDN Magazine]] | publisher=Microsoft | archiveurl=https://web.archive.org/web/20081006195551/http://msdn.microsoft.com/en-us/magazine/cc163293.aspx | archivedate=62008-10-06 October| access-date=2017-06-10 | dead-url=no 2008}}</ref>通过访问不同数据存储中的数据由PowerShell运行,如[[资源管理器]]或[[注册表]]。
 
== 源起與目的 ==
第48行 ⟶ 第49行:
* 具備完整的擴充功能,獨立軟體商或開發者都能很容易的自行擴充。
* 进程间数据传递内容具有强类型特征。
* PowerShell Core 可以自動檢測適合的字符編碼,自動識別 Linux Windows 下的換行符,跨平台运行
 
cmdlet是Windows PowerShell的指令,發音唸法為command-let。這相當於[[DOS]]或其他殼程式的內建指令,指令名稱的格式都是以[[連字號]](-)隔開的一對[[動詞]]和[[名詞]],並且通常都是[[單數 (語言學)|單數]]名詞;例如線上查詢說明的cmdlet指令為get-help,名稱的動詞部分大致有get、set、add、remove等等(字母都不分大小寫)。
第55行 ⟶ 第56行:
 
== 技術基礎 ==
Windows PowerShell是以[[.NET框架|.NET Framework]]技術為基礎,並且與現有的{{tsl|en|WSH||WSH}}保持回溯相容,因此它的腳本程式不僅能存取.NET CLR,也能使用現有的{{tsl|en|COM||COM}}技術。同時也包含了數種系統管理工具、簡易且一致的語法,提升管理者處理,常見如登錄資料庫、WMI。Exchange Server 2007以及System Center Operations Manager 2007等伺服器軟體都將內建Windows PowerShell。
 
== 範例 ==
 
 
* 停止所有目前執行中的以"p"字元開頭命名的程式:
第87行:
</syntaxhighlight>
 
=== 命令提示符等的字元比较 ===
{| class="wikitable plainrowheaders" style="width: 100%; text-align: center; font-size: small;"
|+PowerShell命令行與其他命令行解釋器的內部和外部命令的比較
第101行:
|[[Dir (命令)|dir]]
|[[ls]]
|列出前或文件資料夾中的所有文件檔案文件資料
|-
! scope="row" | Test-Connection{{efn|1=尽管外部[[ping]]命令仍可用於PowerShell,但“Test-Connection”的输出是一个可以通过编程来检查的结构化[[对象 (计算机科学)|对象]]。
<br />
While the external ping command remains available to PowerShell, Test-Connection's output is a structured object that can be programmatically inspected.<ref>{{cite web|title=Test-Connection|url=https://technet.microsoft.com/en-us/library/hh849808.aspx|website=PowerShell documentations|publisher=[[微软]]|date=9 August 2015|access-date=2019-12-18|archive-date=2016-10-31|archive-url=https://web.archive.org/web/20161031104550/https://technet.microsoft.com/en-us/library/hh849808.aspx}}</ref>}}
|[[ping]]
|[[ping]]
|[[ping]]
|從計算機電腦向指定計算機發電腦傳送[[Ping|互聯網控制消息協議回顯請求]],或指示另一台計算機電腦這樣做
|-
! scope="row" | Get-Content
第115行:
|{{tsl|en|TYPE (DOS command)||type}}
|[[Cat (Unix)|cat]]
|文件得檔案內容
|-
! scope="row" | Get-Command
|gcm
|{{tsl|en|help (command)||help}}
|{{tsl|en|type (Unix)||type}}, {{tsl|en|which (command)||which}}, [[{{le|命令行补全|compgen (Unix)|compgen]]}}
|列出可用的命令
|-
第127行:
|{{tsl|en|help (command)||help}}
|{{tsl|en|apropos (Unix)||apropos}}, [[手册页|man]]
|在控制台上打印命令的文
|-
! scope="row" | Clear-Host
|cls, clear
|{{tsl|en|[[cls (computing命令)||cls}}]]
|[[Clear (Unix)|clear]]
|清除屏幕{{efn|Clear-Host被實現為預定義的PowerShell功能。}}
第139行:
|[[Copy (命令)|copy]], {{tsl|en|xcopy|}}, {{tsl|en|robocopy|}}
|[[Cp (Unix)|cp]]
|將文件檔案文件資料夾複製到另一個位置
|-
! scope="row" | Move-Item
第145行:
|{{tsl|en|move (command)||move}}
|[[Mv (Unix)|mv]]
|將文件檔案文件資料夾移動到新位置
|-
! scope="row" | Remove-Item
第151行:
|{{tsl|en|del (command)||del}}, {{tsl|en|del (command)||erase}}, [[rmdir]], [[Rmdir|rd]]
|[[Rm (Unix)|rm]], rmdir
|刪除文件檔案文件資料
|-
! scope="row" | Rename-Item
第157行:
|{{tsl|en|ren (command)||ren}}, rename
|[[Mv (Unix)|mv]]
|重命名單個文件,文件檔案、資料鏈接連結或符號鏈接連結
|-
! scope="row" | Get-Location
第163行:
|[[Cd (命令)|cd]]
|[[pwd]]
|顯示工作路徑(文件資料夾)
|-
! scope="row" | Pop-Location
|popd
|{{tsl|en|pushd and [[Pushd及popd||popd}}]]
|popd
|將工作路徑更改為最近推送到堆上的位置
|-
! scope="row" | Push-Location
|pushd
|{{tsl|en|pushd and [[Pushd及popd||pushd}}]]
|pushd
|將工作路徑到堆
|-
! scope="row" | Set-Location
|sl, cd, chdir
|[[Cd (命令)|cd]], [[Cd (命令)|chdir]]
|cd
|改變工作路徑
第187行:
|{{n/a}}
|[[tee]]
|將輸入管道傳輸到文件檔案或變,並沿管道傳遞輸入
|-
! scope="row" | Write-Output
第199行:
|tlist,{{efn|name="Available tlist kill"|1=Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools}} {{tsl|en|tasklist|}}{{efn|name="Available tasklist taskkill"|1=Available in Windows XP Professional Edition and later}}
|[[Ps (Unix)|ps]]
|列出所有正在行的處理
|-
! scope="row" | Stop-Process
|spps, kill
|{{tsl|en|[[kill (command命令)||kill}}]],{{efn|name="Available tlist kill"}} [[Kill (命令)#Microsoft Windows|taskkill]]{{efn|name="Available tasklist taskkill"}}
|kill{{efn|name="UNIX kill misnomer"|1=Also used in UNIX to send a process any [[Unix信号|signal]], the "Terminate" signal is merely the default}}
|停止正在行的處理
|-
! scope="row" | Select-String
|sls
|{{tsl|en|[[findstr|}}]]
|[[find]], [[grep]]
|打印与模式匹配的-{zh-tw:列;zh-cn:;}-
|-
! scope="row" | Set-Variable
第223行:
|[[CURL|curl]]
|[[wget]], curl
|因特得互联网上的网页內容
|}
{{notelist}}
 
== Windows PowerShell 3.0 ==
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。<ref>{{Cite web|title=PowerShell Version 3 is RTM!|url=https://tfl09.blogspot.com/2012/08/powershell-version-3-is-rtm.html|accessdate=2023-09-09|work=tfl09.blogspot.com|archive-date=2023-09-05|archive-url=https://web.archive.org/web/20230905210224/https://tfl09.blogspot.com/2012/08/powershell-version-3-is-rtm.html|dead-url=no}}</ref><ref>{{Cite web|title=WMF 3.0|url=https://www.microsoft.com/en-us/download/details.aspx?id=34595|accessdate=2023-09-09|work=www.microsoft.com|archive-date=2023-06-19|archive-url=https://web.archive.org/web/20230619114542/https://www.microsoft.com/en-us/download/details.aspx?id=34595|dead-url=no}}</ref>
 
PowerShell 3.0 是一个更大的软件包 Windows Management Framework 3.0 (WMF3) (WMF3) 的一部分。
PowerShell 3.0 是一个更大的软件包 Windows 管理框架 3.0 (WMF3) 的一部分,其中还包含支持远程协作的 WinRM 服务。<ref>{{Cite web|title=Powershell Version|url=https://poshnit.wordpress.com/2015/08/15/125/|accessdate=2023-09-09|work=poshnit.wordpress.com|archive-date=2023-09-05|archive-url=https://web.archive.org/web/20230905210227/https://poshnit.wordpress.com/2015/08/15/125/|dead-url=no}}</ref><ref>{{Cite web|title=Microsoft has released Windows Management Framework 3.0 - Community Technology Preview|url=https://www.ntcompatible.com/story/windows-management-framework-30-community-technology-preview-ctp-1a/|accessdate=2023-09-09|work=www.ntcompatible.com|archive-date=2023-09-05|archive-url=https://web.archive.org/web/20230905210231/https://www.ntcompatible.com/story/windows-management-framework-30-community-technology-preview-ctp-1a/|dead-url=no}}</ref>
 
PowerShell 3.0 的新功能包括:<ref>{{Cite web|title=What Is PowerShell ISE?|url=https://www.easeus.com/knowledge-center/powershell-ise.html|accessdate=2023-09-09|work=www.easeus.com|archive-date=2023-09-05|archive-url=https://web.archive.org/web/20230905210230/https://www.easeus.com/knowledge-center/powershell-ise.html|dead-url=no}}</ref><ref>{{Cite web|title=Introducing Windows 8: An Overview for IT Professionals|url=https://books.google.com/books?vid=ISBN9780735670501&newbks=0|accessdate=2023-09-09|work=books.google.com|archive-date=2023-09-05|archive-url=https://web.archive.org/web/20230905210225/https://books.google.com/books?vid=ISBN9780735670501&newbks=0|dead-url=no}}</ref>
*计划任务:可使用 Windows 任务调度程序基础架构计划任务在预定的时间和日期运行。
*会话重新连接:会话可以断开并重新连接。远程会话现在能更好地应对临时网络故障。
*改进了代码编写:增加了代码自动完成(IntelliSense)和代码片段。PowerShell ISE 允许用户使用对话框填写 PowerShell cmdlet 参数。
*授权支持:可将管理任务授权给无权执行此类任务的用户,而无需授予他们永久性的额外权限。
*更新帮助:可使用 Update-Help 命令更新帮助文档。
 
== 參考文獻 ==
{{reflist}}
<div class="references-small">
<references></references>
</div>
 
== 擴展閱讀 ==
第236行 ⟶ 第247行:
* {{Cite book |title=Windows PowerShell Quick Reference |first=Lee |last=Holmes |isbn=0-596-52813-2 |publisher=[[歐萊禮|O'Reilly Media]] |year=2006}}
* {{Cite book |title=Windows PowerShell Cookbook |first=Lee |last=Holmes |isbn=0-596-52849-3 |publisher=[[歐萊禮|O'Reilly Media]] |year=2007}}
* {{Cite book |title=Professional Windows PowerShell |url=https://archive.org/details/professionalwind0000watt |first=Andrew |last=Watt |isbn=0-471-94693-1 |year=2007 |publisher={{link-en|Wrox Press|Wrox Press}}}}
* {{Cite book |last=Kumaravel |first=Arul |first2=Jon |last2=White |first3=Michael |last3=Naixin Li |first4=Scott |last4=Happell |first5=Guohui |last5=Xie |first6=Krishna C. |last6=Vutukuri |title= Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers |isbn= 0-470-17393-9 |year=2008 |publisher={{link-en|Wrox Press|Wrox Press}}}}
* {{Cite book |title=Windows PowerShell Unleashed |url=https://archive.org/details/windowspowershel0000kopc_i9y6 |first=Tyson |last=Kopczynski |first2=Pete |last2=Handley |first3=Marco |last3=Shaw |isbn=978-0-672-32988-3 |edition=2nd |year=2009 |publisher=[[培生教育|Pearson Education]]}}
* {{Cite book |title=Windows PowerShell 2.0: TFM |url=https://archive.org/details/windowspowershel0000jone |first=Don |last=Jones |first2=Jeffery |last2=Hicks |isbn=978-0-9821314-2-8 |year=2010 |edition=3rd |publisher=Sapien Technologies}}
* {{Cite book |title=Windows PowerShell for Developers |url=https://archive.org/details/windowspowershel0000fink |first=Douglas |last=Finke |isbn=1-4493-2270-0 |year=2012 |publisher=[[歐萊禮|O'Reilly Media]]}}
* {{Cite book |title=Windows PowerShell 3.0 Step by Step |url=https://archive.org/details/windowspowershel0000wils |first=Ed |last=Wilson |isbn=978-0-7356-6339-8 |publisher=[[微软出版社|Microsoft Press]] |year=2013}}
* {{cite book |title=Windows PowerShell Best Practices |last=Wilson |first=Ed |publisher=[[微软出版社|Microsoft Press]] |isbn=978-0-7356-6649-8 |year=2014}}
 
== 外部連結 ==
;微软官网
* [https://docs.microsoft.com/zh-tw/powershell/scripting/how-to-use-docs 如何使用 PowerShell 文件 - PowerShell | Microsoft Docs]
* [http://technet.microsoft.com/-{zh-cn:zh-cn;zh-tw:zh-tw}-/library/bb978526.aspx Windows PowerShell]{{dead link|date=2017年11月 |bot=InternetArchiveBot |fix-attempted=yes }}:PowerShell简介
* [https://github.com/PowerShell/PowerShell GitHub - PowerShell/PowerShell: PowerShell for every system!] {{Wayback|url=https://github.com/PowerShell/PowerShell |date=20200514210658 }}
* [http://technet.microsoft.com/-{zh-cn:zh-cn;zh-tw:zh-tw}-/library/hh847741.aspx Windows PowerShell 3.0 Core Modules]{{dead link|date=2017年11月 |bot=InternetArchiveBot |fix-attempted=yes }}:'''PowerShell 3.0核心模块及模块中的命令用法'''
* [httphttps://msdntechnet.microsoft.com/-{zh-cn:zh-cn;zh-tw:zh-tw}-/library/ms714469dd125460.aspx 易學易用的Windows PowerShell] Reference]{{dead linkWayback|dateurl=2017年11月https://technet.microsoft.com/zh-tw/library/dd125460.aspx |bot=InternetArchiveBot |fix-attempteddate=yes20180108233506 }}
* [https://channel9.msdn.com/Series/GetStartedPowerShell3 MSDN视频教程] {{Wayback|url=https://channel9.msdn.com/Series/GetStartedPowerShell3 |date=20210716070446 }}
* [http://technet.microsoft.com/-{zh-cn:zh-cn;zh-tw:zh-tw}-/scriptcenter/dd742419.aspx 使用 Windows PowerShell 撰寫指令碼]{{dead link|date=2017年11月 |bot=InternetArchiveBot |fix-attempted=yes }}
* [https://technet.microsoft.com/zh-tw/library/dd125460.aspx 易學易用的Windows PowerShell]
* [https://github.com/PowerShell/PowerShell PowerShell源代码]
* [https://channel9.msdn.com/Series/GetStartedPowerShell3 MSDN视频教程]
 
;其他
* {{GitHub|PowerShell/PowerShell}}
* {{tsl|en|TechNet||TechNet}}[[維基]]:[http://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide-en-us.aspx Windows PowerShell Survival Guide] {{Wayback|url=http://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide-en-us.aspx |date=20120915113215 }}
 
{{-}}
第264行 ⟶ 第272行:
{{Microsoft development tools}}
{{程序设计语言}}
{{Unix-Windows互操作性}}
 
[[Category:.NET编程语言]]