Functions/Query/Views/Get-CdsQueryFromFetch.ps1
<#
.SYNOPSIS Retrieve query expression from fetch Xml #> function Get-CdsQueryFromFetch { [CmdletBinding()] param ( [Parameter(Mandatory = $false, ValueFromPipeline)] [Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $CdsClient = $Global:CdsClient, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $FetchXml ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $conversionRequest = New-Object "Microsoft.Crm.Sdk.Messages.FetchXmlToQueryExpressionRequest"; $conversionRequest.FetchXml = $FetchXml; $conversionResponse = $CdsClient.Execute($conversionRequest); $conversionResponse.Query; } end { $StopWatch.Stop(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-CdsQueryFromFetch -Alias *; |