Package Deployer is a great tool to deploy your Dynamics CRM solutions. However, it normally requires human to operate the tool and seldom automated.
Here is how to automate the deploy process using PowerShell.
Step 1 – Register XRM Tooling
First step is to install XRM Tooling SnapIn. Follow this article Use PowerShell cmdlets for XRM tooling to connect to Dynamics 365.
Step 2 – Deploy using PowerShell
Add-PSSnapin Microsoft.Xrm.Tooling.Connector Add-PSSnapin Microsoft.Xrm.Tooling.PackageDeployment $packageDirectory = Get-Location $packageName = "MyPackageDeployer.dll" $username = "administrator@mycrm.onmicrosoft.com" $password = "mypassword" $orgName = "myOrgName" $secstr = New-Object -TypeName System.Security.SecureString $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)} $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr $CRMConn = Get-CrmConnection -DeploymentRegion Oceania -OnlineType Office365 -OrganizationName $orgName -Credential $Cred Import-CrmPackage -CrmConnection $CRMConn -PackageDirectory $packageDirectory -PackageName $packageName -Verbose
The drawback of deploying this way is that it requires Administrator privilege to install those SnapIn, something not available on TFS Online.
Cheers,
Sy
Great post! Is there anyway to enable logging? On my import-CrmPackage command I get to the step Pre-Import process Completed and then powershell crashes with a file not found exception. I was hoping that logging would help me figure out the issue
Hi hayden,
If I’m not mistaken, you can capture the error and prompt or log to file with PowerShell. Unfortunately I haven’t done so myself, but please comment if you have found a solution to this.
Cheers,
Sy