コンテンツにスキップ

PowerShell

出典: フリー百科事典『ウィキペディア(Wikipedia)』
Windows PowerShellから転送)
PowerShell
PowerShell
PowerShellのロゴ
パラダイム 命令型プログラミングオブジェクト指向プログラミング関数型プログラミングリフレクション手続き型プログラミング ウィキデータを編集
登場時期 2006年11月14日 (17年前) (2006-11-14)
設計者 Jeffrey Snover、Bruce Payette、James Truher、他
開発者 マイクロソフト ウィキデータを編集
最新リリース 7.4.3 / 2024年6月18日[1]
型付け 強い型付け型推論動的型付け
影響を受けた言語 Perl、Control Language、PythonKornShellC Sharp、DIGITALコマンド言語、SQLTclTkChef (ソフトウェア)、Puppet、BashPuppet ウィキデータを編集
プラットフォーム Microsoft WindowsWindows ServerUbuntuDebianCentOSRed Hat Enterprise LinuxopenSUSEFedoraArch LinuxmacOS ウィキデータを編集
ライセンス MIT License(Windowsコンポーネントはプロプライエタリ
ウェブサイト
拡張子 .ps1, .psm1
テンプレートを表示
Windows PowerShell
Microsoft Windows コンポーネント
詳細
種別 コマンドライン シェル
標準提供
追加提供
関連コンポーネント
cmd.exe

PowerShell (CLI) .NET Framework (Windows PowerShell 5) .NET Core (PowerShell Core 6) 

Microsoft ShellMSH Monad[2]

Windows 7 (OS) 

[]


OSMS-DOSWindowsCOMMAND.COMMicrosoft Windows NTcmd.exe (GUI) [3][4]

1998Windows 98Windows Script Host (WSH) WSH使WSH

2003WindowsMonad PowerShell

20159Windows PowerShell5.0Windows 10[5]Windows 8.14.0Windows 83.0Windows 72.0[6]

20168PowerShellLinuxOS X6.NET Core[7]

[]

Windows PowerShell[]

Windows PowerShell 1.0[]


20039 Monad20064Windows PowerShell (RC) 120069RC2

200611Windows PowerShell 1.0 (RTW) .NET Framework 2.020071PowerShell 1.0 for Vista

GUIPowerShellExchange Server 2007PowerShellPowerShellcmd.exeWSH

Windows PowerShell 2.0[]


200910

Windows PowerShell 3.0[]


20129.NET Framework4

Windows PowerShell 4.0[]


201310.NET Framework 4.5

Windows PowerShell 5.0[]


201512[ 1][8][9][10].NET Framework 4.5

Windows PowerShell 5.1[]


20168Windows 10 Anniversary UpdateWindows Server 2016

Windows PowerShell 5.1DesktopCore2[ 2]Desktop EditionWindows PowerShellCore EditionNano Server.NET Core[12]
Windows PowerShellのバージョンと対応OS
項目 1.0 2.0 3.0 4.0 5.0
Windows Server 2003 ○SP1 ○SP2 × × ×
Windows Server 2003 R2 ○SP1 ○SP2 × × ×
Windows Server 2008 ○SP1 ○SP1 ○SP2 × ×
Windows Server 2008 R2 ○SP1 ○SP1 ○SP1
Windows Server 2012
Windows Server 2012 R2
Windows XP x64 ○SP1 ○SP2 × × ×
Windows XP ○SP2 ○SP3 × × ×
Windows Vista ○SP1 × × ×
Windows 7 ○SP1 ○SP1 ○SP1
Windows 8 × ×
Windows 8.1
Windows 10
Windows 11

×

PowerShell Core[]

PowerShell Core 6.0[]


20168Linux/OS X[7]

20181PowerShell Core 6.0[13][11].NET Framework.NET Core 2.0使PowerShell Core6WindowsmacOSLinux[14]

PowerShell Core 6.1[]


20189PowerShell Core 6.1[15] Windows 10Windows Server 2019[15].NET Core 2.1使

PowerShell Core 6.2[]


20193PowerShell Core 6.2[16][17]

PowerShell 7.0[]


20203PowerShell 7.0[18][19].NET Core 3.1使

PowerShell 7.1[]


202011PowerShell 7.1[20].NET 5.0使

[]


PowerShell[21][ 3] (cmdlet) .NET[22]

UNIX[23]UNIXgrepawk使

[]


Windows PowerShell/PowerShell Core

[24]

使

 (PowerShell Core)[25]

Windows PowerShellShift-JIS ()PowerShell CoreUTF-8[26]

Windows PowerShell  powershell.exePowerShell Core  pwsh.exe [27][28]

switch (forforeachwhile) (ifswitch) (globalscriptlocal)[29]

-WhatIf-Confirm-WhatIf[30]-Confirm[31]

[32]

PowerShell[33]
dir HKLM:SOFTWARE\Microsoft
PowerShell [34]PowerShell

 (execution policies)PowerShellPowerShellRestrictedAllSignedRemoteSignedUnrestricted[35]

[36]

[37]-show-detailed-informations-s

[38]Windowscmd.exe

[39]

PowerShell0$null12 "@()"[40]
# Get-ChildItem が返戻する要素数が1のため、$bad には サイズ1024バイトのファイルを表すFileInfo型のオブジェクトが代入される。
$bad = Get-ChildItem "1個のサイズ1024バイトのファイルがあるディレクトリ"  
# 一見、$bad.Lengthはディレクトリの要素数1が予想されるが、結果は1024が帰ってくる。$badは配列ではなくFileInfo型のオブジェクトで、Lengthプロパティが1024のためである。
$bad.Length
1024            # !?

# 明示的に配列を返したい場合は"@()"でくくる。
$good = @(Get-ChildItem "1個のサイズ1024バイトのファイルがあるディレクトリ" )
# $goodは正しく要素数1の配列のため、Lengthプロパティは1になる。
$good.Length
1

使用例[編集]

「p」で始まるプロセスを全て停止する[41]

PS> Get-Process p* | Stop-Process

1000 MB以上のメモリを占有するプロセスを検索し、停止する[42]

PS> Get-Process | Where { $_.WS -gt 1000MB } | Stop-Process

ディレクトリ中に含まれる全ファイルの合計サイズを計算して出力する[43]

PS> Get-Childitem | Measure-Object -property length -sum

文字列に含まれる小文字を大文字に変換した文字列を作る[44]

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

"internal"という文字列の5文字目の直後に"natio"という文字列を挿入し、結果として"international"を得る[45]

PS> "internal".Insert(5, "natio")

指定したRSSフィードをダウンロードし、最新の8エントリーのタイトルを表示する[46]

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

脚注[編集]

注釈[編集]



(一)^ Windows PowerShell 5.0Windows Management Framework (WMF) 5.020157Windows10PowerShell 5.0/WMF 5.0OSRTMWMF 5.0201512232016112

(二)^ Core EditionPowerShell Core 5.1PowerShell Core[11]

(三)^ PowerShellMonad: monadology調調[2]

出典[編集]



(一)^ URL: https://github.com/PowerShell/PowerShell/releases/tag/v7.4.3, : 2024624, : Release 7.4.3, : 2024618

(二)^ abPayette 2007, p. 4.

(三)^ Payette 2007, pp. 4, 6.

(四)^ Payette 2007, p. 6.

(五)^ Cool Stuff about PowerShell 5.0 in Windows 10.  Microsoft (201583). 2018928

(六)^ Windows PowerShell .  Microsoft Docs (201765). 2018928

(七)^ abMicrosoftPowerShellLinuxOS X.  OSDN (2016819). 2016820

(八)^ PowerShell Team (20151216). Windows Management Framework (WMF) 5.0 RTM is now available. 2018928

(九)^ PowerShell Team (20151223). Windows Management Framework (WMF) 5.0 currently removed from Download Center. 2018928

(十)^ Windows Management Framework 5.0 (Superceeded by WMF 5.1 RTM version: http://aka.ms/wmf5download).  Microsoft. 2018928

(11)^ abPowerShell Core 6.0: Generally Available (GA) and Supported! (). 2019831

(12)^ Nano Server  PowerShell. 2019831

(13)^ MSPowerShell Core 6.0--LinuxmacOS.  ZDNet Japan (2018112). 20181026

(14)^ PowerShell Core 6.0 .  Microsoft (201886). 20191015

(15)^ abAnnouncing PowerShell Core 6.1 (2018913). 202035

(16)^ General Availability of PowerShell Core 6.2 (2019328). 202035

(17)^ MicrosoftPowerShell Core 6.2PowerShell 7. 201997

(18)^ Announcing PowerShell 7.0 (202034). 202035

(19)^ MicrosoftPowerShell 7.0 null (202035). 202035

(20)^ Announcing PowerShell 7.1 (20201111). 20201112

(21)^ PowerShell.  Microsoft (201886). 20191015

(22)^ Payette 2007, p. 33.

(23)^ Payette 2007, pp. 4960.

(24)^ PowerShell.  Microsoft (2019228). 20191015

(25)^ PowerShell.  Microsoft (2019228). 20191015

(26)^ VSCode  PowerShell .  Microsoft (2019228). 20191015

(27)^ PowerShell exe  - PowerShell.  Microsoft Learn. 2023510

(28)^ Pwsh  - PowerShell.  Microsoft Learn. 2023510

(29)^ Payette 2007.

(30)^ Holmes 2008, pp. 8, 9, 416.

(31)^ Holmes 2008, pp. 8, 9.

(32)^ Payette 2007, pp. 321328.

(33)^ Holmes 2008, pp. 1416.

(34)^ Holmes 2008, pp. 1416, 67, 68.

(35)^ Payette 2007, pp. 510514.

(36)^ Payette 2007, pp. 514527.

(37)^ Holmes 2008, p. 6.

(38)^ Payette 2007, pp. 1719.

(39)^ Payette 2007, p. 160-166.

(40)^ PowerShell Gives You Wrongs. 202029

(41)^ Payette 2007, p. 556.

(42)^ Payette 2007, pp. 556, 557.

(43)^ Payette 2007, pp. 557, 558.

(44)^ Payette 2007, p. 560.

(45)^ Payette 2007, pp. 560, 561.

(46)^ Payette 2007, p. 415.

参考文献[編集]

  • Payette, Bruce 著、株式会社クイープ 訳『Windows PowerShell イン アクション』ソフトバンククリエイティブ、2007年。ISBN 978-4-7973-3736-5 
  • Holmes, Lee『Windows PowerShell クックブック』監訳:マイクロソフト株式会社 ITプロ エバンジェリストチーム, 訳:菅野良二(初版)、オライリー・ジャパン、2008年。ISBN 978-4-87311-382-1 

外部リンク[編集]