Manage Dynamics CRM data and settings with PowerShell!


Hey everyone, I have a new exciting project to share with the community. Kenichiro  and I recently released a scripted PowerShell module (PSM1) called Microsoft.Xrm.Data.Poweshell.  This PowerShell module enables admins to query and manipulate Dynamics CRM Data. It supports On-Prem and Online and primarily targets releases CRM 2013 and greater, however I have been able to connect to CRM 2011 for basic operations.

So, what can you do with this PowerShell module?

  • Query, Create, Update, and Delete CRM records
  • Execute workflows, change business units, assign/remove roles
  • Review plugin traces (in CRM version 7.1+ and higher) and Mailbox Trace data
  • Review customization solution import results (including the result XML)
  • Import, export, and publish customizations
  • much more!

You can download the module by following the link, but I’ve also included installation instructions at the bottom of the post: Xrm.Data.Poweshell: PowerShell for Dynamics CRM Organization Data or you can use the short URL of: https://aka.ms/CRMPowerShell

Why?

Reason #1: customers, our customers have been asking for this and Ken and I wanted to make management and querying CRM data easier and accessible to everyone. While the XrmTooling Powershell snapin provides a connection and proxy back to CRM, the proxy is a bit difficult to work with and admins usually just want to get work done. To enable this, Ken and I targeted the most common operations admins and developers would want based on feedback we've heard in the field with customers. Additionally, we’ve packaged the tooling DLL with our module meaning you don’t have to register the snapin to connect to CRM when using this module.

Also, with CRM onprem and online, admins need a standardized way to query data and configure their instances of CRM (no matter where they're hosted). This module will allow you to import it and get right to work, query data, query metadata, get entity attributes, verify record data that isn't easily viewable in CRM and more. We did our best to follow the common patterns for naming like: 'get-crmRecords', 'connect-CrmOnlineDiscovery'. 

Who should use this?

The target audience for the module is for IT Admins, CRM Admins, and developers - it's very helpful to verify attribute metadata, get record counts, look at entity metadata, etc. The module provides basic and common functions to allow easy downloading and usage of the module. We also released several samples to illustrate common uses.

What’s next?

  • We’re looking at listing this in a repository like Chocolatey (https://chocolatey.org/) so you can install it via OneGet  – this is a work in progress and something we haven’t attempted yet – if you have any tips please share! Smile 
  • I hope to try and get a screencast recorded showing some simple uses of the module to help with getting started quickly
  • We will keep adding more functions to the module, at the same time we'll add more sample scripts so that you can simply modify them and and use them immediately. Any feedback is welcome, so please post Questions in the Q&A section here: https://gallery.technet.microsoft.com/scriptcenter/PowerShell-functions-for-16c5be31/view/Discussions#content 
  • AzureAutomation – currently it appears XrmTooling has some dependencies that we believe are not compatible with Azure Automation (at least not without some tweaking).  Ken and I looking into this, we’ll do what we can to make the current version work or try and get something out to work in Azure Automation if at all possible.

We look forward to your feedback and as always, thanks for reading! 

Sean McNellis & Kenichiro Nakamura


@seanmcne
@pfedynamics | http://www.pfedynamics.com

--------------------------------------------------------------------------------------------

PowerShell Module Installation Instructions:

1. You can download the module here installation instructions are below: Microsoft.Xrm.Data.Poweshell: PowerShell for Dynamics CRM Organization Data

2. Download the zip file and save it to disk

3. Right-click the Zip file and press properties 

4. On the properties page: Check "Unblock" checkbox and click "OK", or simply click "Unblock" the button could look differently depending on the OS.

5. Extract the zip file and copy "Microsoft.Xrm.Data.PowerShell" folder to one of the following folders:
   • %USERPROFILE%\Documents\WindowsPowerShell\Modules
   • %WINDIR%\System32\WindowsPowerShell\v1.0\Modules 

The image below shows this module copied to User Profile. If you want all users to have the module accessible on the computer, copy them to System Wide PowerShell module folder instead. If you do not have the folder, you can manually create them.

6. The module is not signed and you may need to change Execution Policy to load the module. You can do so by executing following command (Please refer to Set-ExecutionPolicy for more information).

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope CurrentUser

 

7. Open PowerShell and run following command to load the module.

Import-Module Microsoft.Xrm.Data.Powershell

8. Here is a sample on how to query all accounts from a CRM Online org called “Contoso”

Import-Module Microsoft.Xrm.Data.Powershell -verbose –force
$me = Get-Credential
$myOrg = Get-CrmConnection -Credential $me -DeploymentRegion NorthAmerica –OnlineType Office365 –OrganizationName CONTOSO -verbose
Get-CrmRecords -conn $myOrg -EntityLogicalName systemuser -Fields *

#now retrieve all users who have a fullname like ‘Sean%’
Get-CrmRecords -conn $myOrg -EntityLogicalName systemuser -Fields * -FieldName fullname -FilterOperator like -FilterValue 'Adventure%'

Comments (6)

  1. Sandeep says:

    Any plans for Orion Sp1 +

  2. It supports the versions listed above (2013 and higher), Orion is 6.0 (aka CRM 2013) and Leo is 6.1 (2013 SP1), Vega is 7.0 (2015) and Carina is 7.1 (online only).  

  3. Kevin Dan says:

    Hi Sean,

    Thank you both for this great Powershell module.

    Just noticed one bug in the last cmd: Test-XrmTimerStop, it trys to get the timer from Global scope, in fact, it's created in Script scope.

    Regards,

    Kevin

  4. Rodrigo Correia says:

    Hi,

    Thanks for this module.

    I'm trying to set this with AzureAutomation but I get the following error when using Get-CrmConnection:

    Error: Get-CrmConnection : The type initializer for 'System.ComponentModel.DesignerProperties' threw an exception.

    At BackupSolutions:40 char:40

    +

       + CategoryInfo          : SyntaxError: (:) [Get-CrmConnection], TypeInitializationException

       + FullyQualifiedErrorId : -9,Microsoft.Xrm.Tooling.CrmConnector.Powershell.Commands.GetCrmConnectionCommand

    Any ideas?

    Thanks,

    Rodrigo

  5. @Rodrigo, in this post we do mention azure automation and a problem with the connector, which you have run into.  We have a workaround however it isn't reliable yet and we're working to see if there's a way to alter the connector code to remove this dependency (unless the interactive switch is used).  Stay tuned!

  6. Oliver Rodrigues says:

    is there a way to import massive data into CRM based on a xml Schema through Command Line ?
    my objective is to automate USD Records import, insted of using Data Migration, I would like to import it by using command lines

Skip to main content