Usage of MgGraph in CloudShell

Herbert 20 Reputation points


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,


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,099 questions
{count} votes

Accepted answer
  1. Vasil Michev 85,481 Reputation points MVP

    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*

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful