개요
레지스트리 프로바이더는 Windows 레지스트리를 HKLM:, HKCU: 드라이브로 노출해, 30장부터 다룬 파일 시스템 조작 cmdlet을 레지스트리에도 그대로 쓸 수 있게 해 준다(Windows 전용). 이 장은 Part 4에서 배운 Get-ChildItem, New-Item, Copy-Item, Move-Item, Rename-Item, Remove-Item, Get-ItemProperty/Set-ItemProperty가 레지스트리라는 구체적인 대상에서 어떻게 조합되는지 정리하며 Part 4를 마무리한다.
지금까지 이 Part의 모든 예제가 파일 시스템을 대상으로 했던 이유는 가장 직관적인 프로바이더이기 때문일 뿐, 다뤄온 cmdlet 자체는 처음부터 특정 프로바이더에 묶여 있지 않았다. 이 장은 그 일반성을 레지스트리라는 전혀 다른 데이터 저장소에 그대로 적용해 실제로 확인하는 자리다.
종류
| 개념 | 파일 시스템 대응 | 다루는 cmdlet |
|---|---|---|
| 레지스트리 키(컨테이너) | 디렉터리 | Get-ChildItem, New-Item, Move-Item, Rename-Item, Remove-Item |
| 레지스트리 값(Item Property) | 파일의 메타데이터/속성 | Get-ItemProperty, New-ItemProperty, Set-ItemProperty, Move-ItemProperty, Rename-ItemProperty, Remove-ItemProperty |
| 기본 드라이브 | — | HKLM:(HKEY_LOCAL_MACHINE), HKCU:(HKEY_CURRENT_USER) |
| 전체 하이브 이름으로 접근 | — | Registry::HKEY_LOCAL_MACHINE\...처럼 프로바이더 이름 + :: 사용 |
값의 데이터 타입(-Type) | — | String(REG_SZ), ExpandString(REG_EXPAND_SZ), Binary, DWord, MultiString, QWord |
레지스트리 반환 타입도 파일 시스템과 대응한다 — 키는 Microsoft.Win32.RegistryKey 객체로, 값은 PSCustomObject로 반환된다.
예시
| |
주의사항·함정
키와 값을 혼동하면 아무것도 못 찾는다: Get-ChildItem은 하위 키만 보여주고, 그 키가 가진 값은 절대 보여주지 않는다. 39장에서 짚었듯 Test-Path도 값의 존재는 확인하지 못한다. “이 레지스트리 데이터가 어디 있는가"를 찾을 때 키를 찾는 중인지 값을 찾는 중인지부터 구분해야 한다.
값을 새로 만들 때 타입을 지정하지 않으면 REG_SZ(문자열)가 기본이다: Set-ItemProperty -Type 동적 매개변수는 Set-Item에도 나타나지만 Set-Item에서는 아무 효과가 없다 — 반드시 Set-ItemProperty나 New-ItemProperty에서 지정해야 한다.
내용이 있는 키를 -Recurse 없이 지우려 하면 항상 확인을 묻는다: 36장에서 다룬 디렉터리 삭제와 동일한 안전장치가 레지스트리 키에도 적용된다. 키만 비우고 자체는 남기려면 Remove-Item -Path 키\*(끝에 백슬래시+와일드카드)를 쓰거나, 값만 지우려면 Clear-Item을 쓴다.
레지스트리 조작은 시스템 전체에 영향을 줄 수 있다: HKLM: 아래 키를 잘못 지우거나 잘못된 타입으로 값을 덮어쓰면 서비스가 시작되지 않거나 운영체제가 불안정해질 수 있다. 프로덕션 시스템에서는 변경 전 Export-Clixml이나 .reg 파일로 백업하고, 가능하면 -WhatIf로 먼저 확인하는 습관이 필요하다.
이식성: CMD의 reg query/reg add/reg delete가 정확히 이 프로바이더의 기능에 대응하지만, 텍스트 기반 명령줄 옵션을 따로 외워야 한다. PowerShell은 지금까지 배운 파일 시스템 cmdlet을 그대로 재사용한다는 점이 근본적으로 다르다 — 이것이 30장에서 소개한 프로바이더 개념이 실제로 배움의 비용을 줄여주는 대표적인 사례다.
![Featured image of post [PowerShell] 40. 레지스트리 프로바이더(Registry:) 다루기](/post/powershell/registry-provider-hklm-hkcu-powershell/wordcloud_hu_96b150a21de8d1c8.webp)
![[PowerShell] 38. Get-ItemProperty/Set-ItemProperty](/post/powershell/get-set-itemproperty-command-powershell/wordcloud_hu_4fee0f6df596d89c.webp)
![[PowerShell] 39. Test-Path — 경로 존재 확인](/post/powershell/test-path-command-check-path-powershell/wordcloud_hu_8b7ea3ad5761442.webp)
![[PowerShell] 40. 레지스트리 프로바이더(Registry:) 다루기](/post/powershell/registry-provider-hklm-hkcu-powershell/wordcloud_hu_cf90c98823ba3b1c.webp)
![[PowerShell] 41. 변수와 데이터 타입](/post/powershell/variables-data-types-powershell/wordcloud_hu_6051f7a36d4700ee.webp)
![[PowerShell] 42. 배열과 컬렉션 기초](/post/powershell/arrays-collections-powershell/wordcloud_hu_c295cc73d4592ae5.webp)
![[PowerShell] 36. Remove-Item — 삭제](/post/powershell/remove-item-command-delete-powershell/wordcloud_hu_85e27bcaf405bed4.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] 33. New-Item — 파일·디렉터리 생성](/post/powershell/new-item-command-create-file-directory-powershell/wordcloud_hu_c75a1ced5c6a3aa3.webp)