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
}

Comment (1)

  1. kevin

    Hi, first excuse me for my bad english i am french 😀

    I want to thank you for this tips but i have one problem, i need a script, i will appreciate if you can help me to resolve this..

    The problem is: i have a key registry (PEACY) that contain subkeys (0, 1 , 101, 100…..) like this for example:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY]

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY]
    “Name”=”Adobe Reader (0)”
    “Status”=”success”
    “Prev_Timestamp”=”2012/09/05 05:05:10”
    “Prev_UpdateVer”=”63”
    “Prev_SubfunctionPkey”=”{68DE7BC5-CCE7-40A9-A222-AB5B98A57895}”
    “LastInstallDate”=”2013-08-21 09:30:30”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1006]
    “Name”=”Microsoft Hotfix Rollout Status (1006)”
    “Status”=”success”
    “UpdateVer”=”3”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1008]
    “Name”=”PEACY Performance Monitor (1015)”
    “Status”=”unavailable”
    “install_never”=”1”

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PEACY\1009]
    “Name”=”PEACY Performance Monitor (1009)”
    “status”=”unavailable”
    “install_never”=”1”
    “hidden”=dword:00000001
    .
    .
    .
    .
    .

    ————————————————

    I want to retrieve on every subkeys keys from (SOFTWARE\Wow6432Node\PEACY\) the content of the “Name” keys, but only if the other keys “Status” contain the value “Success” like my example..and finally store the result on text file to get a list of software name :
    ————————–
    Adobe Reader (0)
    Microsoft Hotfix Rollout Status (1006)

    ————-

    i need you’r help because i am beginner on powershell, thanks for advance 🙂

    Best Regards
    Kevin

Leave a Comment

Your email address will not be published.