1

Is there a way to automatize connecting to MSGraph?

I have found a way to automatize connecting to AzureAD by using next two lines of code, which works perfectly without any pop-up.

$UPN = whoami /upn
Connect-AzureAD -AccountId $UPN

Is there something similar for Connect-MSGraph?

All my google searches on this topic have resulted in automatizing connecting to MgGraph which is not what I need.

Any help would be much appreciated.

jerkdavi
  • 47
  • 2
  • 9

1 Answers1

0

You can automate the connection to MS Graph with Powershell, we gonna need Microsoft.Graph.Authentication which give the Connect-MgGraph needed for connecting to MS Graph.

Dont forget to replace your_client_id your_client_secret and your_tenant_id with your values

Install-Module -Name Microsoft.Graph.Authentication

$clientId = "your_client_id"
$clientSecret = "your_client_secret"
$tenantId = "your_tenant_id"
Connect-MgGraph -ClientSecretCredential $(New-Object Microsoft.Graph.Authentication.ClientSecretCredential -ArgumentList $tenantId, $clientId, $clientSecret)
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
  • If I understand correctly, for this to work I need to create an app in Azure from which I would get client_id and client_secret? What's the purpose of creating such an application? I'm not sure if I need it. Is there a way to do it without creating unnecessary applications? – jerkdavi Mar 22 '23 at 10:55
  • This will get you authenticate and access to Microsoft Graph API – Saxtheowl Mar 22 '23 at 15:59