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

Announcements

News and Announcements icon
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)
  • Suggested answer
    Minghao Yang Profile Picture
    75 on at

    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

  • pawin Profile Picture
    249 on at

    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
  • pawin Profile Picture
    249 on at

    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

  • pholpar Profile Picture
    2 on at
    AuthType=ClientSecret; Url=YourCrmUrl; ClientId=YourClientId; ClientSecret=YourClientSecret
    
    Siehe
    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect
    

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
11manish Profile Picture

11manish 57

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 41 Super User 2026 Season 1

#3
sannavajjala87 Profile Picture

sannavajjala87 25

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans