注册表
对 Registry 操作和 FileSystem 类似,但注意,registry keys 是 item path,registry entries 是 item property。
Hive 路径
Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER
Registry::HKEY_CURRENT_USER
Registry::HKCU
HKCU:
只有 HKCU:
和 HKLM:
,其它的得用 Registry::
。
Set-Location HKCU:\Software
Get-ChildItem -Name
Get
# 过滤 keys
Get-ChildItem -Path HKCU:\Software -Recurse | Where-Object -FilterScript {($_.SubKeyCount -le 1) -and ($_.ValueCount -eq 4) }
# 获取 key 全部 entries
Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion
# 获取 entry
Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion -Name DevicePath
# 获取 entry 的值
Get-ItemPropertyValue -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name PowerShellVersion
Set
Set-ItemProperty -PropertyType
Create
# 创建 key
New-Item
# 创建 entry
New-ItemProperty
Remove
# 清空 entries
Clear-Item HKLM:\Software\MyCompany\MyKey -Confirm
# 删除 entry
Remove-ItemProperty
# 删除 entry 的值
Clear-ItemProperty