Jump to content

PowerShell

This is a fully translated article. Click here for more information.
From DawoumWiki, the free Mathematics self-learning
PowerShell
Screenshot of a PowerShell Core session in Windows Terminal
ParadigmImperative, pipeline, object-oriented, functional and reflective
Designed byJeffrey Snover, Bruce Payette, James Truher (et al.)
DeveloperMicrosoft
First appearedNovember 14, 2006; 17 years ago (2006-11-14)
Stable release
7.2.0 / November 9, 2021; 2 years ago (2021-11-09)[2]
Preview release
v7.2.0-rc.1[1] / October 23, 2021; 2 years ago (2021-10-23)
Typing disciplineStrong, safe, implicit and dynamic
Implementation languageC#
Platform.NET Framework, .NET Core
OS
LicenseMIT License[3] (but the Windows component remains proprietary)
Filename extensions
  • .ps1 (Script)
  • .ps1xml (XML Document)
  • .psc1 (Console File)
  • .psd1 (Data File)
  • .psm1 (Script Module)
  • .pssc (Session Configuration File)
  • .psrc (Role Capability File)
  • .cdxml (Cmdlet Definition XML Document)
Influenced by
Python, Ksh, Perl, C#, CL, DCL, SQL, Tcl, Tk,[4] Chef, Puppet


PowerShell 또는 Microsoft PowerShell (이전의 Windows PowerShell)은 명령-줄 과 결합된 스크립팅 언어로 구성된 마이크로소프트의 임무 자동화와 구성 관리 프로그램입니다. 처음에는 Windows PowerShell로 알려진 윈도우 구성 요소 전용이었지만, 그것은 PowerShell Core의 도입으로 2016년 8월 18일에 오픈-소스크로스-플랫폼이 되었습니다.[5] 전자는 .NET Framework에 구축되고, 후자는 .NET Core에 구축됩니다. Windows PowerShell이라는 이름은 여전히 최신 버전의 윈도우 11과 10에 존재하지만, 최신 버전의 PowerShell은 PowerShell 또는 Microsoft PowerShell이라고 불립니다.

PowerShell에서, 관리 임무는 일반적으로 특정 연산을 구현하는 특수 .NET 클래스를 전무화되는 cmdlets (command-lets으로 발음)에 의해 수행됩니다. 이것들은 providers를 통해 PowerShell에서 사용할 수 있게 만드는 파일 시스템 또는 레지스트리와 같은 다른 데이터 저장소에서 데이터에 접근함으로써 작동합니다. 타사 개발자는 PowerShell에 cmdlet와 providersf를 추가할 수 있습니다.[6][7] Cmdlet은 스크립트에 의해 사용될 수 있게 되며, 그것은 차례로 모듈로 패키지될 수 있습니다.

PowerShell은 COMWMI에 대한 접근을 제공하여, 관리자에게 로컬 및 원격 윈도우 시스템뿐만 아니라 원격 리눅스 시스템 및 네트워크 장치의 관리를 가능하게 하고 마찬가지로 WS-ManagementCIM에서 관리 작업을 수행할 수 있도록 합니다. PowerShell은 역시 PowerShell 런타임이 다른 응용 프로그램 내부에 삽입될 수 있는 호스팅 API를 제공합니다. 이들 응용 프로그램은 그런-다음 PowerShell 기능을 그래픽 인터페이스를 통해 노출되는 연산을 포함하여 특정 연산을 구현하기 위해 사용할 수 있습니다. 이 가능성은 Microsoft Exchange Server 2007에 의해 관리 기능을 PowerShell cmdlet와 providers로 표시하고 그래픽 관리 도구를 필요한 cmdlet을 호출하는 PowerShell 호스트로 구현하기 위해 사용되었습니다.[6][8] Microsoft SQL Server 2008을 포함한 다른 마이크로소프트 응용 프로그램도 PowerShell cmdlet을 통해 관리 인터페이스를 노출합니다. [9]

PowerShell은 Get-Help cmdlet을 통해 접근할 수 있는 자체적인 광범위한 콘솔-기반 도움말 (유닉스 쉘매뉴얼 페이지와 유사)을 포함하고 있습니다. 업데이트된 로컬 도움말 내용은 Update-Help cmdlet을 통해 인터넷에서 검색될 수 있습니다. 대안적으로, 웹에서 도움말은 -online 스위치를 Get-Help로 전환하여 사례별로 획득될 수 있습니다.

Comparison of cmdlets with similar commands

윈도우 10에서, 파워셸은 Windows Powershell 아래에 Windows Powershell의 명령으로 제공됩니다. 이전에 사용하던 명령 프롬프트Windows 시스템아래에 명령어가 존재합니다.

아래 표에서, 2열은 파워셸에서 사용하는 명령어입니다. 물론 1열에 있는 긴 명령어를 사용할 수도 있지만, 너무 길어서 짧게 별칭으로 만든 것, 2열을 이용합니다. 3열은 명령 프롬프트이고 4열은 리눅스(Unik-like) 등에서 사용하는 명령어입니다.

파워셸과 명령 프롬프트, 그리고 리눅스 셸의 경로에 대한 차이점이 있습니다. 어떤 명령어를 실행하는 방법은 절대 경로로 실행하는 방법과 상대 경로로 실행하는 방법이 있습니다.

절대 경로는 최상위 디렉토리부터 현재 명령어까지 전체를 입력하는 방법입니다. 상대 경로는 현재 프롬프트 위치에서 명령어까지 찾아가는 경로입니다.

예를 들어, 프롬프트가 어떤 위치에 있더라도 c:\Temp\adb\adb.exe devices와 같이 실행하는 것이 절대 경로를 이용하는 방법입니다. 일반적으로 상대 경로를 주로 이용하는데, 이 경우에도 명령어가 있는 디렉토리, 예를 들어 c:\Temp\adb로 이동한 후에, 즉 현재 디렉토리에서, 명령 adb devices와 입력하는 방식입니다.

한편, 상대 경로에서 파워셸과 명령 프롬프트 사이에 차이가 생깁니다. 파워셸은 .\adb devices와 같이 현재 디렉토리를 나타내는 .\를 반드시 입력해야 명령어가 실행됩니다. 반면에 명령 프롬프트는 현재 디렉토리를 나타내는 경로를 입력해도 되고, 입력하지 않아도 명령어가 실행됩니다. 참고로 리눅스에서는 ./가 현재 디렉토리를 나타내고, 상대 경로에서 반드시 입력을 해야 실행됩니다.

파워셸과 명령 프롬프트의 공통점은 확장자를 입력해도 되고 안해도 된다는 점입니다. 즉, 경로를 제외하고 명령어 adbadb.exe는 같은 효력을 나타냅니다.

또한, 파워셸과 명령 프롬프트에서는 대소문자를 구별하지 않습니다. 절대 경로 경우의 예제에서 처럼, C:\tEMp\AdB\aDB.Exe devices와 같이 다소 이상한 일력에도 정상적인 반응을 합니다. 그러나, 마지막의 명령어 인수는 대소문자를 구별합니다. 명령어 인수는 adb.exe에서 정의하고, 윈도우 운영체제나 윈도우 내부 명령어와는 상관없이 별도로 정의됩니다. 반면에 리눅스는 대소문자를 항상 구별합니다.

Comparison of PowerShell cmdlets with internal and external commands of other command-line interpreters
PowerShell (Cmdlet) PowerShell (Alias) Windows Command Prompt Unix shell Description
Get-ChildItem gci, dir, ls dir ls Lists all files and folders in the current or given folder
Test-Connection[a] ping ping ping Sends ICMP echo requests to the specified machine from the current machine, or instructs another machine to do so
Get-Content gc, type, cat type cat Gets the content of a file
Get-Command gcm help type, which, compgen Lists available commands
Get-Help help, man help apropos, man Prints a command's documentation on the console
Clear-Host cls, clear cls clear Clears the screen[b]
Copy-Item cpi, copy, cp copy, xcopy, robocopy cp Copies files and folders to another location
Move-Item mi, move, mv move mv Moves files and folders to a new location
Remove-Item ri, del, erase, rmdir, rd, rm del, erase, rmdir, rd rm, rmdir Deletes files or folders
Rename-Item rni, ren, mv ren, rename mv Renames a single file, folder, hard link or symbolic link
Get-Location gl, cd, pwd cd pwd Displays the working path (current folder)
Pop-Location popd popd popd Changes the working path to the location most recently pushed onto the stack
Push-Location pushd pushd pushd Stores the working path onto the stack
Set-Location sl, cd, chdir cd, chdir cd Changes the working path
Tee-Object tee N/A tee Pipes input to a file or variable, passing the input along the pipeline
Write-Output echo, write echo echo Prints strings or other objects to the standard output
Get-Process gps, ps tlist,[c] tasklist[d] ps Lists all running processes
Stop-Process spps, kill kill,[c] taskkill[d] kill[e] Stops a running process
Select-String sls findstr find, grep Prints lines matching a pattern
Set-Variable sv, set set env, export, set, setenv Creates or alters the contents of an environment variable
Invoke-WebRequest iwr, curl, wget[f] N/A wget, curl Gets contents from a web page on the Internet

Notes

  1. ^ While the external ping command remains available to PowerShell, Test-Connection's output is a structured object that can be programmatically inspected.[10]
  2. ^ Clear-Host is implemented as a predefined PowerShell function.
  3. ^ a b Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
  4. ^ a b 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 are absent from PowerShell Core, so as to not interfere with invoking similarly named components of non-Windows OSes.

See also

References

  1. ^ "PowerShell 7.2.0 RC1 now available for testing - MSPoweruser".
  2. ^ "PowerShell/PowerShell". GitHub. Retrieved 2021-11-09.
  3. ^ "PowerShell for every system!". 12 June 2017 – via GitHub.
  4. ^ Snover, Jeffrey (May 25, 2008). "PowerShell and WPF: WTF". Windows PowerShell Blog. Microsoft.
  5. ^ Bright, Peter (2016-08-18). "PowerShell is Microsoft's latest open source release, coming to Linux, OS X". Ars Technica. Condé Nast. Archived from the original on 2020-04-09. Retrieved 2020-05-12.
  6. ^ a b "How Windows PowerShell works". Microsoft Developer Network. Microsoft. Retrieved 2007-11-27.
  7. ^ Truher, Jim (December 2007). "Extend Windows PowerShell With Custom Commands". MSDN Magazine. Microsoft. Archived from the original on 6 October 2008.
  8. ^ Lowe, Scott (January 4, 2007). "Exchange 2007: Get used to the command line". TechRepublic. CBS Interactive. Archived from the original on 2018-11-16. Retrieved 2020-05-12.
  9. ^ Snover, Jeffrey (2007-11-13). "SQL Server Support for PowerShell!". Windows PowerShell Blog (blog posting). Microsoft. Archived from the original on 2007-11-15. Retrieved 2007-11-13.
  10. ^ "Test-Connection". PowerShell documentations. Microsoft. 9 August 2015.

Further reading

External links