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

Announcements

No record found.

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
11manish Profile Picture

11manish 174

#2
ManoVerse Profile Picture

ManoVerse 58 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans