src/SQL/Disable-XrmTdsEndpoint.ps1

<#
    .SYNOPSIS
    Disable TDS endpoint.
    
    .DESCRIPTION
    Configure orgdbsettings parameter to prevent 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 false (see Set-XrmOrganizationDbSetting).

    .EXAMPLE
    Disable-XrmTdsEndpoint -XrmClient $xrmClient;

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

function Disable-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 "false";
    }
    end {
        $StopWatch.Stop();
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

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