개요
프로바이더(provider)는 레지스트리, 인증서 저장소, 환경 변수, 함수 목록처럼 원래 파일 시스템이 아닌 데이터를 파일 시스템과 똑같은 방식(드라이브·경로·cd·dir)으로 다룰 수 있게 해 주는 .NET 프로그램이다. 4장부터 다룬 Get-ChildItem, Test-Path 같은 cmdlet이 파일뿐 아니라 레지스트리 키에도 그대로 통하는 이유가 바로 이 프로바이더 계층 덕분이다.
정신 모델은 “PowerShell은 계층 구조를 가진 어떤 데이터든 드라이브라는 동일한 틀에 끼워 넣는다"는 것이다. C:가 파일 시스템의 진입점이듯, HKLM:은 레지스트리의, Cert:는 인증서 저장소의, Env:는 환경 변수의 진입점이다 — 이 모든 드라이브를 같은 Get-ChildItem/Set-Location/Get-Item 세트로 탐색할 수 있다.
종류
| 프로바이더 | 드라이브 | 노출하는 객체 타입 |
|---|---|---|
| FileSystem | C: 등 | System.IO.FileInfo, System.IO.DirectoryInfo |
| Registry(Windows 전용) | HKLM:, HKCU: | Microsoft.Win32.RegistryKey |
| Certificate(Windows 전용) | Cert: | X509Certificate2 |
| Alias | Alias: | AliasInfo |
| Environment | Env: | DictionaryEntry |
| Function | Function: | FunctionInfo |
| Variable | Variable: | PSVariable |
| WSMan(Windows 전용) | WSMan: | WS-Management 구성 요소 |
프로바이더가 지원하는 cmdlet은 공통이다 — Get-ChildItem, Get-Item, New-Item, Copy-Item, Move-Item, Remove-Item, Rename-Item, Get-ItemProperty 계열, Set-Location/Push-Location/Pop-Location, Test-Path 등은 어느 드라이브에서든 똑같이 동작한다.
예시
| |
주의사항·함정
모든 프로바이더가 모든 플랫폼에서 동작하지는 않는다: Registry, Certificate, WSMan 프로바이더는 Windows 전용이다. 크로스플랫폼 스크립트를 작성한다면 $IsWindows 자동 변수로 분기하거나, 애초에 FileSystem·Environment·Variable처럼 모든 플랫폼에 있는 프로바이더만 의존하도록 설계해야 한다.
프로바이더마다 동적 매개변수가 다르게 추가된다: 예를 들어 Cert: 드라이브는 Get-ChildItem에 -CodeSigningCert 같은 프로바이더 전용 매개변수를 추가한다. 이런 매개변수는 그 드라이브 안에서만 나타나므로, 다른 드라이브에서 같은 cmdlet을 쓸 때는 보이지 않는다고 당황할 필요 없다.
Get-PSDrive가 보여주는 드라이브가 전부는 아니다: 어떤 프로바이더는 모듈을 임포트해야 비로소 드라이브가 나타난다. 필요한 드라이브가 안 보이면 관련 모듈이 로드됐는지부터 확인한다.
이식성: CMD·Bash에는 파일 시스템 외의 데이터를 “탐색 가능한 경로"로 노출하는 개념 자체가 없다 — 레지스트리를 다루려면 reg.exe처럼 완전히 별도의 도구·문법을 배워야 한다. PowerShell 프로바이더는 서로 다른 데이터 저장소를 배우는 비용을 “이미 아는 파일 시스템 명령을 다른 경로에 쓰는 것"으로 크게 낮춘다.
![Featured image of post [PowerShell] 30. PSDrive와 프로바이더 개념](/post/powershell/psdrive-provider-concept-powershell/wordcloud_hu_28d443ab70fa48d.webp)
![[PowerShell] 28. Add-Member — 커스텀 객체에 속성·메서드 추가](/post/powershell/add-member-command-custom-object-properties-powershell/wordcloud_hu_5d862fe677def637.webp)
![[PowerShell] 29. Write-Host vs Write-Output — 출력 스트림 오개념 정리](/post/powershell/write-host-vs-write-output-streams-powershell/wordcloud_hu_cd68b845a7c59766.webp)
![[PowerShell] 30. PSDrive와 프로바이더 개념](/post/powershell/psdrive-provider-concept-powershell/wordcloud_hu_48d84a64f7474c4.webp)
![[PowerShell] 31. Get-ChildItem — 파일·디렉터리 목록](/post/powershell/get-childitem-command-file-directory-list-powershell/wordcloud_hu_3e00080e70b06aa7.webp)
![[PowerShell] 32. Set-Location/Push-Location/Pop-Location](/post/powershell/set-location-push-pop-location-powershell/wordcloud_hu_b555782207661429.webp)
![[PowerShell] 35. Move-Item/Rename-Item — 이동과 이름 변경](/post/powershell/move-rename-item-command-powershell/wordcloud_hu_cb2a58d584784b24.webp)
![[PowerShell] 36. Remove-Item — 삭제](/post/powershell/remove-item-command-delete-powershell/wordcloud_hu_85e27bcaf405bed4.webp)
![[PowerShell] 33. New-Item — 파일·디렉터리 생성](/post/powershell/new-item-command-create-file-directory-powershell/wordcloud_hu_c75a1ced5c6a3aa3.webp)
![[PowerShell] 34. Copy-Item — 복사](/post/powershell/copy-item-command-copy-file-powershell/wordcloud_hu_ebeda4bcc9a1c9ff.webp)