PowerShell via Xrm.Tooling.Connector and cleaning up USD Entities

So I found myself sitting in a USD training class the other day….

At the tail end of the Extreme CRM conference in Madrid this last week ( 4/2015 ) I found myself sitting in a USD Training class, when a situation came up where a student had “broken” their deployment.  Suffice to say that a bunch of records had been corrupted in such a way that it made sense to dump the USD data in the org and start over. 

The easiest way that folks in the class came up with to fix this was to remove the USD solutions, which in turn removed the data for USD.  The downside of that is that it takes a while to uninstall / reinstall solutions. 

PowerShell to the rescue

As an odd happenstance,  I had built a PowerShell script a few weeks before to clean up USD environments that I use when testing builds of USD. I turned it into a demo to show at the Dynamics Technical Conference with the intention of blogging it ( yea I know, long time between posts… ).   And here I found an application for this.

So what does this script do?

As folks know (or may not know) we added a PowerShell cmdlet to CRM 2013 Sp1 ( 6.1) called Microsoft.Xrm.Tooling.Connector.Powershell. This cmdlet allows us to create an instance of the CrmServiceClient connector to CRM and use the functions of CRM from any given PowerShell script.  With that I took advantage of a little know feature of the CRM API ‘s Bulk Delete capability to send multiple queries on one bulk delete request.

With that, the Bulk delete items and some defensive scripting,  I end up with a script that will remove all the records from a USD configuration in one call to CRM

Run the command which prompts for login…
image

Answer the are you sure… really??????
THIS WILL WIPE OUT ALL OF YOUR USD CONFIG DATA WITH NO GOING BACK TO IT.

image

You were warned and said ok anyway….
Now you get to look at a status of this happening and contemplate if you picked the right environment while you wait….

image

annnd volia !  Empty USD Deployment

in this case, 1400 rows across 23 entities.  … total time to run … about 1 min.

So how do you do this?

First you need to get the CRM SDK for 2015,  I would recommend the 7.0.1 version or later as we solved a few issue with the –interactive flag of connector in later versions.  you can get that here

Once you have that downloaded.. locate the “bin” directory.. that’s usually <”yourInstallPath”>\SDK\Bin

In that directory you will find a script called RegisterXrmTooling.ps1.  You will need to run the script as an administrator in PowerShell so that it can do what it needs to do to register the connector.  When you register it from this directory, you will likely get a message that says “Did Not Find Microsoft.Xrm.Tooling.PackageDeployment.Powershell.Dll” that’s Ok for this task. you can ignore it.

image

Once you have registered, you should be good to go.. 

You can also use that script to unregister the addin’s by passing the –Uninstall switch to it.

You can get the script I use HERE.. *** No warrantees implied / treat it as samples and such ***

and be aware that THIS WILL WIPE OUT ALL OF YOUR USD CONFIG DATA WITH NO GOING BACK TO IT.

Happy CRMing and such.

Comments

  • Anonymous
    April 23, 2015
    Thanks Matt, That's a life saver :)