Share via

Usage of MgGraph in CloudShell

Herbert 20 Reputation points
2023-05-01T07:15:18.1533333+00:00

Hi,

We updated most of our powershell scripts to use MgGraph (migrated from using Connect-AzureAD to Connect-MgGraph, including the migration to the new <verb>-Mg<resource> commands.)

We do have a few scripts we normally use from Azure Cloud Shell (Powershell variant).

Interestingly Azure Cloud Shell does not support Connect-MgGraph by default,

$EnvironmentAadTenantId = "<AAD tenant ID here..>"
Connect-AzureAD -TenantId $EnvironmentAadTenantId
# or variant
Connect-AzureAD -ApplicationId $EnvironmentAadServicePrincipalApplicationId -TenantId $EnvironmentAadTenantId -CertificateThumbprint $EnvironmentAadServicePrincipalCertificateThumbprint  

and it also does not allow to Import the modules

Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Applications

So although the usage of AzureAD module is planned for deprecation and usage of MgGraph is the way forward, then how should we use MgGraph in scripts ran from Azure Cloud Shell?

Best regards,

Herbert

Microsoft Security | Microsoft Graph

Answer accepted by question author

Vasil Michev 127K Reputation points MVP Volunteer Moderator
2023-05-01T16:05:35.7833333+00:00

I don't remember if it comes pre-installed or I added it beforehand, but you can certainly add it. Try

Install-Module Microsoft.Graph

or if already installed,

Update-Module -Name Microsoft.Graph*

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.