Automate your Dynamics CRM Builds and Deployments with PowerShell
Microsoft provides lots of PowerShell commands “cmdlets” that allow you to manage Windows Servers (IIS, File System, Registry) and applications such as Microsoft Office.
The xRM CI Framework provides you with PowerShell “cmdlets” to allow you to script some of the task that are done manually during the build and/or deployment of Dynamics CRM Solutions.
Using the custom “cmdlets” you are able to assemble a script that can be triggered during your TFS build process or executed on demand from your desktop or other automation tools.
Below is a list of “cmdlets” that are available in the initial release:
|CmdLet Name||Description||SDK Message|
|Import-XrmSolution||Imports a CRM Solution||ImportSolutionRequest|
|Export-XrmSolution||Exports a managed or unmanaged CRM Solution||ExportSolutionRequest|
|Get-XrmSolution||Retrieves CRM Solution details using the unique solution name||Not Applicable|
|Publish-XrmCustomizations||Publishes all customizations for a CRM organization||PublishAllXmlRequest|
|Add-XrmEntity||Create a new entity in CRM||CreateRequest|
|New-XrmEntity||Creates a new instance of the Entity class||Not Applicable|
|Set-XrmEntity||Updates an existing entity in CRM||UpdateRequest|
|Remove-XrmEntity||Deletes an existing entity from CRM||DeleteRequest|
Note that most cmdlets will accept the “ConnectionString” parameter. The format is based on the SDK connection string and the cmdlet will use that parameter to connect to CRM.
To get started follow the setup instructions in my previous post.
To get more information about the parameters each cmdlet provides, run the Get-Help cmdlet as shown below from the PowerShell Console. More information on PowerShell can be found in the PowerShell getting started manual. All the parameters are inline with the Dynamics CRM SDK messages of the corresponding cmdlets as shown in the table above.
The next step is to write your first PowerShell Script. Below is a sample script that checks the version of the currently deployed CRM solution and updates the target system if the version deployed is older than the latest version.
This library contains only a subset of what you can do with Dynamics CRM. You can expose any Dynamics CRM SDK message as a PowerShell cmdlet and use it to automate anything that you could be doing manually today.
Having your builds and deployment automated will allow you to build and deploy quickly and will give you the added consistency and reliability.
In future posts, I will show you how you can implement continuous integration by combining the automated builds discussed in this post and the PowerShell cmdlets for Dynamics CRM.