Functions/Client/Add-CdsRecord.ps1

<#
    .SYNOPSIS
    Create entity record in CDS.
#>

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

        [Parameter(Mandatory=$true, ValueFromPipeline)]
        [Microsoft.Xrm.Sdk.Entity]
        $Record
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
    }    
    process {
        $response = Protect-CdsCommand -ScriptBlock { $CdsClient.Create($Record) };
        $response;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

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