web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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. 

I have the same question (0)
  • pawin Profile Picture
    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
    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
    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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 394

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 123

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 106 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans