개요
Get-ItemProperty/Set-ItemProperty는 항목 자체가 아니라 그 항목의 속성을 조회·설정하는 cmdlet이다. 파일 시스템에서는 LastAccessTime이나 IsReadOnly 같은 파일 속성을, 레지스트리에서는 키 안의 값(레지스트리 값, “Item Property"라고 부른다)을 다룬다.
정신 모델은 “레지스트리 키는 컨테이너(디렉터리에 대응)이고, 그 안의 값은 컨테이너의 속성(파일 자체가 아니라 파일의 메타데이터에 대응)“이라는 것이다. 그래서 Get-ChildItem으로는 레지스트리 값이 보이지 않는다 — 값은 자식 항목이 아니라 부모 키의 속성이기 때문에 Get-ItemProperty로 따로 조회해야 한다.
사용법
| |
매개변수
| 매개변수 | 대상 | 설명 |
|---|---|---|
-Name | 둘 다 | 조회·설정할 속성(값) 이름. Get-ItemProperty에서는 와일드카드 지원, 생략 시 모든 속성 반환 |
-Value | Set-ItemProperty | 설정할 값 |
-Type(Registry 동적 매개변수) | Set-ItemProperty | String(REG_SZ), DWord(REG_DWORD), Binary, MultiString, QWord 등 레지스트리 값 타입 지정(기본 String) |
-InputObject | Set-ItemProperty | 파이프로 받은 객체의 속성을 바로 변경 |
예시
| |
주의사항·함정
레지스트리 값을 만들 때는 Set-ItemProperty와 New-ItemProperty 중 무엇을 써도 되지만 의미가 다르다: Set-ItemProperty는 값이 없으면 만들고 있으면 덮어쓰는 하나의 명령이고, New-ItemProperty는 명시적으로 새로 만드는 것이 목적인 명령이다(타입을 처음부터 지정하기에 더 자연스럽다). 이미 있는 값을 실수로 다른 타입으로 덮어쓰지 않으려면, 존재 여부가 불확실할 때 New-ItemProperty로 시작하는 편이 의도가 분명하다.
Get-Item으로는 레지스트리 값이 보이지 않는다: Get-Item HKLM:\SOFTWARE\ContosoCompany는 키 자체의 정보만 주고, 그 안에 설정한 값(NoOfEmployees 등)은 Get-ItemProperty로 별도 조회해야 나타난다. 이 구분을 모르면 “분명히 값을 저장했는데 안 보인다"는 혼란에 빠지기 쉽다.
레지스트리 값 타입을 지정하지 않으면 기본이 문자열(String)이다: 숫자로 저장해야 하는 값을 -Type을 지정하지 않고 Set-ItemProperty로 새로 만들면 REG_SZ(문자열)로 저장되어, 그 값을 읽는 다른 프로그램이 숫자를 기대할 경우 오작동할 수 있다. 새 레지스트리 값을 만들 때는 -Type DWord처럼 명시하는 습관이 안전하다.
이식성: CMD의 reg add/reg query, Bash에는 대응하는 표준 개념이 없다(레지스트리 자체가 Windows 고유 개념). 파일 속성 조회·설정 측면에서는 CMD의 attrib이 Get-ItemProperty/Set-ItemProperty의 아주 좁은 부분집합에 대응한다.
![Featured image of post [PowerShell] 38. Get-ItemProperty/Set-ItemProperty](/post/powershell/get-set-itemproperty-command-powershell/wordcloud_hu_3bdfa9c8b0c158d0.webp)
![[PowerShell] 36. Remove-Item — 삭제](/post/powershell/remove-item-command-delete-powershell/wordcloud_hu_85e27bcaf405bed4.webp)
![[PowerShell] 37. Get-Content/Set-Content/Add-Content](/post/powershell/get-set-add-content-command-powershell/wordcloud_hu_f8c9bc65df09a5fa.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] 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)
![[PowerShell] 35. Move-Item/Rename-Item — 이동과 이름 변경](/post/powershell/move-rename-item-command-powershell/wordcloud_hu_cb2a58d584784b24.webp)