Deployment · Dynamics CRM 2016 · Power Shell · Tools

CRM 2016: Use PowerShell to run Package Deployer

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 = ""
$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.



2 thoughts on “CRM 2016: Use PowerShell to run Package Deployer

  1. 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

    1. 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s