한국   대만   중국   일본 
PowerShell - ?基百科,自由的百科全? 跳?到?容

PowerShell

本页使用了标题或全文手工转换
?基百科,自由的百科全?
PowerShell
Windows Terminal ??行的PowerShell 7
?程范型 命令式 管道 面向?象 函?式 反射式
設計者 杰弗里·史?威 英? Jeffrey Snover (Jeffrey Snover)
布?斯·?耶特(Bruce Payette)
詹姆斯·特?赫(James Truher) (et al.)
實作者 Microsoft
?行?? 2006年11月14日 ,​17年前 ​( 2006-11-14
?前版本
  • 7.4.2 (2024年4月11日;穩定版本) [1]
編輯維基數據鏈接
型態系統 强?型 ?型安全 ?型推? ???型
系?平台 PowerShell: .NET
Windows PowerShell: .NET?架
操作系? Windows 7 及其后?版本、 Linux macOS
許可證 MIT許可證 [2] (但Windows?件仍然是 ?有的
文件?展名
  • .ps1 (脚本文件)
  • .ps1xml(XML文?)
  • .psc1(控制台文件)
  • .psd1(?据文件)
  • .psm1(脚本模?)
  • .pssc(??配置文件)
  • .cdxml (Cmdlet定?的XML文?)
網站 microsoft .com /powershell 編輯維基數據鏈接
?發語言
Ksh Perl C# CL 英? IBM i Control Language DCL 英? DIGITAL Command Language 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 ),同時也內建?本語言以及輔助?本程式的工具。

程式特性 [ ?? ]

  • 一致性的設計讓所有工具和系統資料的使用語法、命名原則都相同。
  • ?本語言簡單易學,而且能支援現有的?本程式和命令列工具。
  • 內含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。

範例 [ ?? ]

  • 停止所有目前執行中的以"p"字元開頭命名的程式:
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

命令提示字元比? [ ?? ]

PowerShell命令行與其他命令行解釋器的內部和外部命令的比較
PowerShell(命令行) PowerShell(別名) 命令提示符 Unix shell 描述
Get-ChildItem gci, dir, ls dir ls 列出目前或指定資料夾中的所有?案和資料夾
Test-Connection [a] ping ping ping 從目前電腦向指定電腦傳送 Ping ,或指示?一台電腦這樣做
Get-Content gc, type, cat type 英? TYPE (DOS command) cat 取得?案內容
Get-Command gcm help 英? help (command) type 英? type (Unix) , which 英? which (command) , compgen 列出可用的命令
Get-Help help, man help 英? help (command) apropos 英? apropos (Unix) , man 在控制台上打印命令的文?
Clear-Host cls, clear cls 英? cls (computing) clear ?除?幕 [b]
Copy-Item cpi, copy, cp copy , xcopy 英? xcopy , robocopy 英? robocopy cp 將?案和資料夾複製到?一個位置
Move-Item mi, move, mv move 英? move (command) mv 將?案和資料夾移動到新位置
Remove-Item ri, del, erase, rmdir, rd, rm del 英? del (command) , erase 英? del (command) , rmdir , rd rm , rmdir 刪除?案或資料夾
Rename-Item rni, ren, mv ren 英? ren (command) , rename mv 重命名單個?案、資料夾、硬連結或符號連結
Get-Location gl, cd, pwd cd pwd 顯示工作路徑(目前資料夾)
Pop-Location popd popd 英? pushd and popd popd 將工作路徑更改?最近推送到堆疊上的位置
Push-Location pushd pushd 英? pushd and popd 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 英? tasklist [d] ps 列出所有正在執行的處理程序
Stop-Process spps, kill kill 英? kill (command) , [c] taskkill [d] kill [e] 停止正在執行的處理程序
Select-String sls findstr find , grep 打印?模式匹配的行
Set-Variable sv, set set 英? Environment variable#DOS env, export, set, setenv ?建或更改 ?境?量 的內容
Invoke-WebRequest iwr, curl, wget [f] curl wget , curl 取得互??上的??內容
  1. ^ ?管外部 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]
  2. ^ Clear-Host被實現?預定義的PowerShell功能。
  3. ^ 3.0 3.1 Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
  4. ^ 4.0 4.1 Available in Windows XP Professional Edition and later
  5. ^ Also used in UNIX to send a process any signal , the "Terminate" signal is merely the default
  6. ^ curl and wget aliases are absent from PowerShell Core, so as to not interfere with invoking similarly named native commands.

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。 [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 命令更新?助文?。

參考文獻 [ ?? ]

  1. ^ 1.0 1.1 Release 7.4.2 . 2024年4月11日 [2024年4月25日] .  
  2. ^ PowerShell LICENSE . [ 2017-06-10 ] . ( 原始?容 存?于2022-05-11).  
  3. ^ Snover, Jeffrey. PowerShell and WPF: WTF . Windows PowerShell Blog. Microsoft. 2008-05-25 [ 2017-06-10 ] . ( 原始?容 存?于2019-01-08).  
  4. ^ Bright, Peter. PowerShell is Microsoft's latest open source release, coming to Linux, OS X . Ars Technica . Conde Nast . 2016-08-18 [ 2017-06-10 ] . ( 原始?容 存?于2022-04-28).  
  5. ^ How Windows PowerShell works . Microsoft Developer Network . Microsoft . [ 2007-11-27 ] . ( 原始?容 存?于2008-09-05).  
  6. ^ Truher, Jim. Extend Windows PowerShell With Custom Commands . MSDN Magazine (Microsoft). December 2007 [ 2017-06-10 ] . (原始?容 存? 于2008-10-06).  
  7. ^ Test-Connection . PowerShell documentations. 微? . 9 August 2015 [ 2019-12-18 ] . ( 原始?容 存?于2016-10-31).  
  8. ^ PowerShell Version 3 is RTM! . tfl09.blogspot.com. [ 2023-09-09 ] . (原始?容 存? 于2023-09-05).  
  9. ^ WMF 3.0 . www.microsoft.com. [ 2023-09-09 ] . (原始?容 存? 于2023-06-19).  
  10. ^ Powershell Version . poshnit.wordpress.com. [ 2023-09-09 ] . (原始?容 存? 于2023-09-05).  
  11. ^ Microsoft has released Windows Management Framework 3.0 - Community Technology Preview . www.ntcompatible.com. [ 2023-09-09 ] . (原始?容 存? 于2023-09-05).  
  12. ^ What Is PowerShell ISE? . www.easeus.com. [ 2023-09-09 ] . (原始?容 存? 于2023-09-05).  
  13. ^ Introducing Windows 8: An Overview for IT Professionals . books.google.com. [ 2023-09-09 ] . (原始?容 存? 于2023-09-05).  

擴展閱讀 [ ?? ]

外部連結 [ ?? ]

微?官?
其他