Remove-pseRegistryValueName.ps1

function Remove-pseRegistryValueName {
    <#
    .SYNOPSIS
    Removes a registry value from a specified key.
 
    .DESCRIPTION
    The Remove-pseRegistryValueName function removes a registry value from the specified key.
 
    .PARAMETER KeyPath
    Specifies the path of the registry key.
 
    .PARAMETER ValueName
    Specifies the name of the registry value to remove.
 
 
    .EXAMPLE
    PS> Remove-pseRegistryValueName -KeyPath "HKCU:\Software\Test" -ValueName "TestValue"
 
 
    .EXAMPLE
    Remove-pseRegistryValueName -KeyPath "HKCU:\Software\Test" -ValueName "NonExistentValue"
 
 
    .NOTES
    Author: owen.heaume
    Version: 1.0.0 - Initial version
    #>

    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [Parameter(Mandatory = $true)]
        [String]$KeyPath,

        [Parameter(Mandatory = $true)]
        [String]$ValueName
    )

    try {
        # Check if the registry key exists
        $keyExists = Test-Path -Path $KeyPath

        if (-not $keyExists) {
            Write-Host "$KeyPath does not exist" -ForegroundColor DarkYellow
            return
        }

        # Check if the registry value exists
        $value = Get-ItemProperty -Path $KeyPath -Name $ValueName -ErrorAction SilentlyContinue

        if (-not $value) {
            Write-Host "'$ValueName' not found" -ForegroundColor DarkYellow
            return
        }

        # Remove the registry value
        if ($PSCmdlet.ShouldProcess("$KeyPath\$ValueName", "Remove")) {
            Remove-ItemProperty -Path $KeyPath -Name $ValueName -Force | Out-Null
        }
    } catch {
        Write-Error "Failed to remove registry value: $_"
    }
}