Private/Resolve-SqlSpnFciCno.ps1

# =============================================================================
# Script : Resolve-SqlSpnFciCno.ps1
# Author : Keith Ramsey
# =============================================================================
# Change Log
# -----------------------------------------------------------------------------
# 2026-05-09 Keith Ramsey Phase 2 release polish - DR-202 standard header applied.
# =============================================================================
function Resolve-SqlSpnFciCno {
    <#
    .SYNOPSIS
        Resolves an FCI virtual SQL name to its Cluster Virtual Computer Account (CNO/VCO).
    .DESCRIPTION
        SQL FCI registers SPNs against the Virtual Computer Object that the cluster
        creates when the SQL role is brought online (e.g., SQLFCI01$). This function
        looks that computer object up in Active Directory by SAM account name.

        Returns an object with Found = $true and the resolved DistinguishedName +
        SamAccountName on success. Returns Found = $false with a Reason on lookup
        failure (object not found, ambiguous match, AD module not loaded, etc.).
    .PARAMETER VirtualName
        The SQL virtual network name (e.g., 'SQLFCI01' or 'SQLFCI01.contoso.com').
    #>

    [CmdletBinding()]
    param([Parameter(Mandatory=$true)][string]$VirtualName)

    $shortName = ($VirtualName -split '\.', 2)[0]

    try {
        $cno = Get-ADComputer -Identity $shortName -ErrorAction Stop
        return [PSCustomObject]@{
            Found             = $true
            SamAccountName    = $cno.SamAccountName
            DistinguishedName = $cno.DistinguishedName
        }
    }
    catch {
        return [PSCustomObject]@{
            Found  = $false
            Reason = $_.Exception.Message
        }
    }
}