Private/Storage/ActiveDirectory/Remove-PukAdRecord.ps1

function Remove-PukAdRecord {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string]$AttributeName,

        [Parameter(Mandatory)]
        [string]$DistinguishedName,

        [string]$Server
    )

    Import-PukActiveDirectoryModule

    $getAdUserParams = @{
        Identity    = $DistinguishedName
        Properties  = @($AttributeName)
        ErrorAction = 'Stop'
    }
    if ($Server) { $getAdUserParams.Server = $Server }

    $user = Get-ADUser @getAdUserParams

    if ([string]::IsNullOrEmpty($user.$AttributeName)) {
        throw "No record found for '$DistinguishedName' in attribute '$AttributeName'."
    }

    if (-not $PSCmdlet.ShouldProcess($DistinguishedName, 'Remove PWSHPUKMGT Active Directory record')) {
        return
    }

    $setAdUserParams = @{
        Identity    = $DistinguishedName
        Clear       = @($AttributeName)
        ErrorAction = 'Stop'
    }
    if ($Server) { $setAdUserParams.Server = $Server }

    Set-ADUser @setAdUserParams
}