Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 3 – using client id (App ID) and certificate for connecting graph – Connect-MgGraph

PowerShell - Exploring Connect-MgGraph - Connecting Microsoft Graph using client id and certificate
PowerShell - Exploring Connect-MgGraph - Connecting Microsoft Graph using client id and certificate

Hi All,

Greetings for the day!

Continuing on my favorite topic – Microsoft Graph PowerShell.

This is 3rd article in the series. In this article we will continue to explore – Connect-MgGraph CMDLET, we will explore – how to connect Microsoft Graph using AppId / ClientId and certificate

If you are beginner to Microsoft Graph PowerShell, please have a look at following article once

Details

Microsoft Entra admin center - App registration
fig : Microsoft Entra admin center – App registration
self sign certificate generated
fig : self sign certificate generated

self sign certificate generated
fig : self sign certificate generated
  • Once we generated certificate we need to export it to upload to our App
  • We will use – Export-Certificate CMDLET to export the certificate as
$certToExport = (Get-ChildItem -Path f97ef453d78e31ba3c6151bd066d92b7fcbd377b)

#specify the path where you need to download the certificate
Export-Certificate -Cert $certToExport -FilePath "C:\Users\prasham\Downloads\graphapi.pfx"

Upload the certificate to the App

Microsoft Entra admin center - App registration page - list of all apps
fig : Microsoft Entra admin center – App registration page – list of all apps
Microsoft Entra admin center - App overview page
fig : Microsoft Entra admin center – App overview page
  • To upload certificate, click on “Certificates & secrets” link from left menu as shown in above snap
  • We will be redirecting to app – “Certificates & secrets” page as
Microsoft Entra admin center - App | "Certificates & secrets" page

  • We will upload certificate from the above page
  • Once certificate uploaded successfully , we will have certificate details on the page as
Microsoft Entra admin center - App | "Certificates & secrets" page - certificate uploaded successfully
fig : Microsoft Entra admin center – App | “Certificates & secrets” page – certificate uploaded successfully
  • Here, take a not of – Thumbprint – will be using while connecting to Microsoft Graph

Connect to Graph API with App ID using the Certificate

  • To connect Microsoft Graph using we will require
    • Tenant ID / Directory ID
    • App ID / Client ID
    • Certificate ThombPrint

#Parameters for Tenant ID and Client ID
$TenantID = “6b38e1c3-a1fe-40cc-8b93-a4159a50592c”
$ClientID = “a2073b4e-14e4-448a-a449-39022286c03c” #App ID
$CertThumbPrint = “F97EF453D78E31BA3C6151BD066D92B7FCBD377B”

#Connect to Microsoft Graph using App
Connect-MgGraph -ClientID $ClientID -TenantId $TenantID -CertificateThumbprint $CertThumbPrint

Output:

PS Cert:\CurrentUser\My> #Parameters for Tenant ID and Client ID
$TenantID = “6b38e1c3-a1fe-40cc-8b93-a4159a50592c”
$ClientID = “a2073b4e-14e4-448a-a449-39022286c03c” #App ID
$CertThumbPrint = “F97EF453D78E31BA3C6151BD066D92B7FCBD377B”

#Connect to Microsoft Graph using App
Connect-MgGraph -ClientID $ClientID -TenantId $TenantID -CertificateThumbprint $CertThumbPrint
Welcome To Microsoft Graph!

PS Cert:\CurrentUser\My>

PowerShell - Exploring Connect-MgGraph - Connecting Microsoft Graph using client id and certificate
fig : PowerShell – Exploring Connect-MgGraph – Connecting Microsoft Graph using client id and certificate

REFERENCES

Thanks for reading ! Stay tuned for more articles on Microsoft Graph PowerShell and PowerShell !

HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

2 Responses

  1. January 27, 2024

    […] Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 3 – using client id (App ID) and certificate for connecting graph – Connect-MgGraph – https://microsoft365hub.in/2024/01/21/m365-msgraph-powershell-tutorial-part-3-using-client-id-app-id… […]

  2. February 1, 2024

    […] In part 3 of the series we explored CMDLET – Connect-MgGraph – Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 3 – using client id (App ID) and certificate for connecting graph – Connect-MgGraph – https://microsoft365hub.in/2024/01/21/m365-msgraph-powershell-tutorial-part-3-using-client-id-app-id… […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading