Functions/Client/Invoke-CdsRequest.ps1
<#
.SYNOPSIS Execute Organization Request. #> function Invoke-CdsRequest { [CmdletBinding()] [OutputType([Microsoft.Xrm.Sdk.OrganizationResponse])] param ( [Parameter(Mandatory=$false, ValueFromPipeline)] [Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $CdsClient = $Global:CdsClient, [Parameter(Mandatory=$true)] [Microsoft.Xrm.Sdk.OrganizationRequest] $Request, [Parameter(Mandatory = $false)] [Switch] $Async ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { if($Async) { $innerRequest = $Request $Request = New-Object -TypeName Microsoft.Xrm.Sdk.Messages.ExecuteAsyncRequest; $Request.Request = $innerRequest; } $response = Protect-CdsCommand -ScriptBlock { $CdsClient.Execute($Request) }; $response; } end { $StopWatch.Stop(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Invoke-CdsRequest -Alias *; |