Public/Get-pseRegistryValue.ps1

function Get-pseRegistryValue {
    <#
    .SYNOPSIS
        Retrieves a specific registry value from the specified registry path.
 
    .DESCRIPTION
        The Get-pseRegistryValue function retrieves a specific registry value from the Windows Registry. You can specify
        the registry path and the name of the value you want to retrieve. If the specified registry value is found, it is
        returned. If the value is not found or an error occurs during the retrieval process, the function returns $null.
 
    .PARAMETER RegistryPath
        Specifies the registry path from which to retrieve the value..
 
    .PARAMETER RegistryValueName
        Specifies the name of the registry value to retrieve.
 
    .EXAMPLE
        Get-pseRegistryValue -RegistryPath "HKLM:\SOFTWARE\CustomSoftware" -RegistryValueName "CustomId"
        Retrieves a custom registry value named "CustomId" from the specified registry path.
 
    .NOTES
        Author : owen.heaume
        Version : 1.0.0 - Initial release
    #>


    [cmdletbinding()]

    param(
        [Parameter(Mandatory = $true)]
        [string]$RegistryPath,

        [Parameter(Mandatory = $true)]
        [string]$RegistryValueName
    )

    try {
        Write-Host "Retrieving value [$RegistryValueName] from registry path [$RegistryPath ]"
        $regValue = (Get-ItemProperty -Path $RegistryPath -Name $RegistryValueName -ea stop).$registryValuename
        return $regValue
    } catch {
        Write-Error "Unable to retrieve value [$RegistryValueName] from registry. Error: $_"
    }
}