MgGraph with Azure Automation Runbook

Mattps 5 Reputation points
2024-01-24T11:25:25.9866667+00:00

Hi,

I am trying to use MgGraph in an Azure runbook but keep hitting a dead end and would appreciate any suggestions. I have the MgGraph modules loaded in the Automation account and credentials saved in the credentials section of the automation account. To test I am just trying to connect to MgGraph first but failing to even do this. This is my PowerShell code:

$Cred = Get-AutomationPSCredential -Name "#######"
Install-Module -Name Microsoft.Graph
Connect-MgGraph -ClientID $TAECred -TenantID "########-####-####-####-############"

The error I receive is:

Connect-MgGraph : The term 'Connect-MgGraph' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:5 char:1 + Connect-MgGraph -ClientID $Cred -TenantID "########-####-####-#### ... + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-MgGraph:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Any ideas?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,196 questions
{count} votes