Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Connecting to Dynamics 365 online using powershell

(0) ShareShare
ReportReport
Posted on by 249

I've been using Microsoft.Xrm.Data.Powershell to read/write data from my online tenant. I now need to run this as an application user rather than my own user. I have registered Dynamics as an Azure App.

How can I connect to the online tenant using this app registrations (i.e. with client ID and secret) rather than supplying a username and password? Both Connect-CrmOnline and Get-CrmConnection need a password. 

  • pawin Profile Picture
    pawin 249 on at
    RE: Connecting to Dynamics 365 online using powershell

    Nowhere to provide the secret though, only the client Id? The latest version package details (www.powershellgallery.com/.../3.3.0.862) include:

    Added Support for ClientID Secret Auth when using oAuth flows. (connection string support )

    however there are no examples of what the connection string should look like in order to do that

  • Suggested answer
    Minghao Yang Profile Picture
    Minghao Yang 75 on at
    RE: Connecting to Dynamics 365 online using powershell

    I believe it also supports OAuth authentication:

    pastedimage1570008212063v1.png

    https://docs.microsoft.com/en-us/powershell/module/microsoft.xrm.tooling.crmconnector.powershell/get-crmconnection?view=dynamics365ce-ps#parameters

  • pawin Profile Picture
    pawin 249 on at
    RE: Connecting to Dynamics 365 online using powershell

    Thanks but as I mentioned I'm using Microsoft.Xrm.Data.Powershell and need to connect via Connect-CrmOnline or Get-CrmConnection. These appear to require Credential that takes username and password.

  • Suggested answer
    Minghao Yang Profile Picture
    Minghao Yang 75 on at
    RE: Connecting to Dynamics 365 online using powershell

    Hello,

    I believe want you need is to connect with application & an application user set up in CRM with application ID:

    Connect using the application secret

    If you are connecting using an secret configured for the application, you will use the ClientCredential class passing in the clientId and clientSecret rather than a UserCredential with userName and password parameters.

    Sample code C#:

    ===============

    string serviceUrl = "yourorg.crm.dynamics.com";

    string clientId = "<your app id>";

    string secret = "<your app secret>";

    AuthenticationContext authContext = new AuthenticationContext("login.microsoftonline.com/common", false);

    ClientCredential credential = new ClientCredential(clientId, secret);

    AuthenticationResult result = authContext.AcquireToken(serviceUrl, credential);

    string accessToken = result.AccessToken;

    ===============

    This could be found from

    docs.microsoft.com/.../authenticate-oauth

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans