PowerApps / Microsoft Flow – Access your CDS using PowerShell

Recently Microsoft have added the Common Data Services to Powerapps and PowerShell. I is great to have a central place to store data, however configuring all the entities can be painful if you have to click through all the options. The new solution model helps you to move configurations between different environments, but still it is a lot of mouse clicks to get all the work done. I’ve been looking for an option to script my custom solutions and I found that it was less than easy to get started.

There isn’t a CDS specific PowerShell available, therefor I started by looking at the CRM/XRM option available. Quite Quickly I stumbled upon  Sean McNellis’s PowerShell tools.

I started by downloading Microsoft Dynamics 365 (v8.x) Software Development Kit (SDK) as the Microsoft.Xrm.Data.PowerShell Powershell tools depend on this being installed.

Once I had the tools installed I started by trying to get the details out of my CDS environment. The Connect-CRMOnlinDiscovery cmdlet got this all sorted out for me.

Connections

Connect-CrmOnlineDiscovery -InteractiveMode

After Setting the Deployment Type and the login details

I received the output for my environment for my default environment

If you want to get to a different environment simply select the Display list of organisations.

Once connected you can get details on  the connection using the Get-CRMConnection Cmdlet.

Time to have a look at the Entities.

Access Entities through PowerShell

I’m using the Entity account as a starting point. Using the Get-CrmEntityAttributes it is possible to get all details for the Entity. Note that the EntityLogicalName is the name

Get-CrmEntityAttributes -EntityLogicalName "account"

Note that the above cmdlet is case sensitive and only the Entity’s Name will work.

 

Data Management in CDS using PowerShell

Now I want to take this further I want to be able to add data to my entities.

Using the following commend I can create new records, get record, update records and delete record

New-CrmRecord -EntityLogicalName account -Id $accountId -Fields name
Set-CrmRecord -CrmRecord $account
Get-CrmRecord -EntityLogicalName account -Id $accountId -Fields name
Remove-CrmRecord  -CrmRecord $account

 

 

 

Advertisements


Categories:Dynamics 365, Flow, Microsoft Flow, Office 365, PowerApps

Tags:

2 replies

  1. Hi Pieter – Thank you for posting this information. I am looking to see how many records are in our CDS in preperation for an upgrade from the legacy to new CDS format. I’m assuming the get-records might be a way to do this. Any thoughts? Suggestions? Thanks, Craig

    Like

Leave a Reply to Craig Davis Cancel reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: