src/SQL/Enable-XrmTdsEndpoint.ps1

<#
    .SYNOPSIS
    Enable TDS endpoint.
    
    .DESCRIPTION
    Configure orgdbsettings parameter to allow SQL commands thru TDS Endpoint.

    .PARAMETER XrmClient
    Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient)

    .OUTPUTS
    System.Void. The EnableTDSEndpoint setting is set to true (see Set-XrmOrganizationDbSetting).

    .EXAMPLE
    Enable-XrmTdsEndpoint -XrmClient $xrmClient;
    $accounts = Invoke-XrmSqlCommand -XrmClient $xrmClient -Command "SELECT TOP 10 name FROM account";

    .LINK
    https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Enable-XrmTdsEndpoint.md
#>

function Enable-XrmTdsEndpoint {
    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([System.Void])]
    param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient]
        $XrmClient = $Global:XrmClient

    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);        
    }    
    process {            
        Set-XrmOrganizationDbSetting -XrmClient $XrmClient -Name "EnableTDSEndpoint" -Value "true";
    }
    end {
        $StopWatch.Stop();
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Enable-XrmTdsEndpoint -Alias *;