Functions/Client/Remove-CdsRecord.ps1

<#
    .SYNOPSIS
    Remove entity record in CRM.
#>

function Remove-CdsRecord {
    [CmdletBinding()]
    param
    (    
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.Xrm.Tooling.Connector.CrmServiceClient]
        $CdsClient = $Global:CdsClient,

        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.Xrm.Sdk.Entity]
        $Record,

        [Parameter(Mandatory = $false)]
        [string]
        $LogicalName,

        [Parameter(Mandatory = $false)]
        [Guid]
        $Id,

        [Parameter(Mandatory=$false)]
        [switch]
        $BypassCustomPluginExecution = $false
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
    }    
    process {

        if(-not ($PSBoundParameters.ContainsKey('Record'))) {
            $Record = New-CdsEntity -LogicalName $LogicalName -Id $Id;
        }

        $request = New-CdsRequest -Name "Delete";
        $request | Add-CdsRequestParameter -Name "Target" -Value $Record.ToEntityReference() | Out-Null;
        if($BypassCustomPluginExecution)
        {
            $request | Add-CdsRequestParameter -Name "BypassCustomPluginExecution" -Value $true | Out-Null;
        }

        $response = Invoke-CdsRequest -Request $request;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Remove-CdsRecord -Alias *;