创建

# 创建注册表项
$registryKey = "HKLM:\SOFTWARE\Example"
$registryItem = New-Item -Path $registryKey -Force

读取

# 读取注册表
$registryKey = "HKLM:\SOFTWARE\Example"
$registryItem = Get-Item -Path $registryKey
Write-Host "注册表项内容:"
$registryItem.GetValueNames() | ForEach-Object { Write-Host "$_ = $($registryItem.GetValue($_))" }

修改

# 添加或修改值
$propertyName = "TestValue"
$propertyValue = "This is a test value"
Set-ItemProperty -Path $registryKey -Name $propertyName -Value $propertyValue

删除

# 删除注册表值
$registryKey = "HKLM:\SOFTWARE\Example"
$propertyName = "TestValue"
Remove-ItemProperty -Path $registryKey -Name $propertyName

# 删除整个注册表项
$registryKey = "HKLM:\SOFTWARE\Example"
Remove-Item -Path $registryKey -Recurse -Force