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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,520 questions
{count} votes

Accepted answer
  1. Vasil Michev 109.9K Reputation points MVP
    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*

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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