Microsoft

Basic PowerShell Registry Value Helpers

Working with registry values in PowerShell can be a little cumbersome, so here are some example helpers that I am using to simplify some of my configuration scripts.

Function Get-RegistryValue {
    param (
        $key,
        $value
    )
 
    (Get-ItemProperty -Path $key -Name $value).$value
}
 
Function Test-RegistryValue {
    param (
        $key,
        $value
    )
 
    $data = Get-ItemProperty -Path $key -Name $value -ErrorAction SilentlyContinue
 
    if ($data) {
        $true
    }
    else {
        $false
    }
}
 
Function Set-RegistryValue {
    param (
        $key,
        $value,
        $data
    )
 
    Set-ItemProperty -Path $key -Name $value -Value $data
}
 
Function New-RegistryValue {
    param (
        $key,
        $value,
        $data = "",
        $propertyType = "String" #Default to string registy value types
    )
 
    New-ItemProperty -Path $key -Name $value -Value $data -PropertyType $propertyType | Out-Null
}
 
Function Remove-RegistryValue {
    param (
        $key,
        $value
    )
 
    Remove-ItemProperty -Path $key -Name $value | Out-Null
}
 
Function Rename-RegistryValue {
    param (
        $key,
        $value,
        $newValue
    )
 
    Rename-ItemProperty -Path $key -Name $value -NewName $newValue
}