Functions/Solutions/Set-CdsSolutionVersion.ps1

<#
    .SYNOPSIS
    Set solution version.
#>

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

        # TODO : Add argument completer with unmanaged solution unique names
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $SolutionUniqueName,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Version
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {
        Write-HostAndLog -Message "Set version $Version to solution $($SolutionUniqueName)..." -Level INFO;
        $solution = $CdsClient | Get-CdsRecord -LogicalName "solution" -AttributeName "uniquename" -Value $SolutionUniqueName -Columns "version";
        if(-not $solution)
        {
            Write-HostAndLog -Message "Solution $SolutionUniqueName not found" -Level WARN;
            return $null;
        }
        $solutionToUpdate = New-CdsEntity -LogicalName "solution" -Id $solution.Id;
        $solutionToUpdate = $solutionToUpdate | Set-CdsAttributeValue -Name version -Value $Version;
        $solutionToUpdate | Update-CdsRecord -CdsClient $CdsClient;
        
        Write-HostAndLog -Message "Solution $SolutionUniqueName has been successfully updated to version : $Version!" -Level SUCCESS;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Set-CdsSolutionVersion -Alias *;