dist/temp/WindowsUpdateTools/Private/Test-WUCOMObject.ps1

function Test-WUCOMObject {
    <#
    .SYNOPSIS
        Tests the availability of the core Windows Update COM object.
    .DESCRIPTION
        This private function attempts to create an instance of the "Microsoft.Update.Session"
        COM object to verify it is registered and available. This helps diagnose
        fundamental issues with the Windows Update Agent API.
    .EXAMPLE
        Test-WUCOMObject
    .NOTES
        Returns $true if the object can be created, $false otherwise.
    #>

    [CmdletBinding()]
    param()

    Write-WULog -Level Verbose -Message "Testing 'Microsoft.Update.Session' COM object availability..."
    $session = $null
    try {
        $session = New-Object -ComObject "Microsoft.Update.Session" -ErrorAction Stop
        if ($session) {
            Write-WULog -Level Verbose -Message "COM object 'Microsoft.Update.Session' created successfully."
            return $true
        }
    }
    catch {
        Write-WULog -Level Error -Message "Failed to create 'Microsoft.Update.Session' COM object."
        Write-WULog -Level Error -Message "Error Type: $($_.Exception.GetType().FullName)"
        Write-WULog -Level Error -Message "Error Message: $($_.Exception.Message)"
        return $false
    }
    finally {
        if ($session) {
            [System.Runtime.InteropServices.Marshal]::ReleaseComObject($session) | Out-Null
        }
    }
    # Should not be reached, but as a fallback
    return $false
}