Connect-MgGraph

Roger Roger 6,611 Reputation points
2024-11-23T22:46:20.5+00:00

I want to connect to Azure MS Graph using an Azure Service Principal. How can I generate a certificate for the Azure Service Principal? I have the Client ID and Tenant ID. I need to fetch users information from Azure AD, and I have the required Graph API permissions. Can I connect using a client secret instead of a certificate

Connect-MgGraph -ClientId “{clientID}” -TenantId “{TenantID}” -CertificateThumbprint “{Thumbprint}”

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,653 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,584 questions
Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,646 questions
{count} votes

Accepted answer
  1. Yakun Huang-MSFT 8,355 Reputation points Microsoft Vendor
    2024-11-25T02:25:14.4066667+00:00

    Hello Roger Roger,

    Thank you for reaching out to Microsoft Support!

    You can connect using the client secret as follows:

    $ClientSecretCredential = Get-Credential -Username "Client_Id"
    # Enter client_secret in the password prompt.
    Connect-MgGraph -TenantId "Tenant_Id" -ClientSecretCredential $ClientSecretCredential
    

    Reference document:

    https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/docs/authentication.md

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Roger Roger 6,611 Reputation points
    2024-11-24T04:09:47.91+00:00

    when i try to connect using client secret i am getting error.

    : Cannot bind parameter 'ClientSecretCredential'. Cannot convert the "mysecret" value of type "System.String" to type "System.Management.Automation.PSCredential".

    At line:1 char:129

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.