Functions/Client/Set-CdsClientTimeout.ps1
<#
.SYNOPSIS Specify CrmserviceClient timeout. #> function Set-CdsClientTimeout { [CmdletBinding()] param ( [Parameter(Mandatory=$false, ValueFromPipeline)] [Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $XrmClient = $Global:XrmClient, [Parameter(Mandatory = $false)] [Switch] $Revert ) dynamicparam { $dynamicParameters = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary; # Define Dynamic Parameter : Duration $durationParameterAttributes = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]; $durationParameterAttribute = New-Object System.Management.Automation.ParameterAttribute; $durationParameterAttribute.Mandatory = (-not $Revert); $durationParameterAttributes.Add($durationParameterAttribute); $durationParameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter("DurationInMinutes", [int], $durationParameterAttributes); $dynamicParameters.Add("DurationInMinutes", $durationParameter); return $dynamicParameters; } begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { if(-not $XrmClient.OrganizationServiceProxy) { return; } $durationInMinutes = $PSBoundParameters.DurationInMinutes; if ($durationInMinutes) { $Global:XrmClientInitialTimeout = $XrmClient.OrganizationServiceProxy.Timeout.TotalMinutes; $XrmClient.OrganizationServiceProxy.Timeout = (New-TimeSpan -Minutes $durationInMinutes); } if ($Revert) { $XrmClient.OrganizationServiceProxy.Timeout = (New-TimeSpan -Minutes $Global:XrmClientInitialTimeout); } } end { $StopWatch.Stop(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Set-CdsClientTimeout -Alias *; |