Connect-MgGraph

Roger Roger 7,631 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}”

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
Microsoft Security | Microsoft Entra | Other

Answer accepted by question author
Anonymous
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.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Roger Roger 7,631 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

    Was this answer helpful?

    0 comments No comments

Your answer

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