Functions/Solutions/Publish-CdsCustomizations.ps1

<#
    .SYNOPSIS
    Publish customizations
#>

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

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [String]
        $ParameterXml,

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

        $publishRequest =  New-Object -TypeName Microsoft.Crm.Sdk.Messages.PublishAllXmlRequest;
        if($ParameterXml)
        {
            $publishRequest = New-Object -TypeName Microsoft.Crm.Sdk.Messages.PublishXmlRequest;
            $publishRequest.ParameterXml = $ParameterXml;
        }

        # Run request with extended timeout
        $CdsClient | Set-CdsClientTimeout -DurationInMinutes $TimeOutInMinutes;
        $response = $CdsClient | Invoke-CdsRequest -Request $publishRequest;
        $CdsClient | Set-CdsClientTimeout -Revert;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Publish-CdsCustomizations -Alias *;