Update Microsoft.Graph Modules on Azure Automation with Managed Identity

Hi All,

The Microsoft.Graph Modules are updated very often. It annoyed me to update these Modules on my Azure Automation Account.

I have now written a Azure Automation Runbook to automate the Update of the Microsoft.Graph Modules.
It uses Managed Identity and updates the PowerShell 5.1 and 7.1 Modules.


As mentioned the Azure Automation Account has a system assigned Service Principal


That Service Principal needs Contributor Permissions on the Azure Automation Account


To use PowerShellGet (Find-Module) i need to first install the Module "PackageManagement"


Now i am able to install the PowerShell Module "PowerShellGet"


As you can see the Microsoft.Graph PowerShell Modules are all on Version 1.23.0


When i run the Update it get's the newest Module Version from the PowerShell Gallery and uninstalls the specified Microsoft.Graph Modules and installs the new version.
The Challenge is that you have to install Microsoft.Graph.Authentication and wait until it's installed. Because all other Microsoft.Graph PowerShell Modules have that as a dependency and will fail if it's not installed beforehand.

The whole Script can be found at my GitHub Repo


I am proud that it not only updates the PowerShell 5.1 Modules but also updates the PowerShell 7.1 Modules.


Here you go. All the Modules are on the newest version from PowerShell Gallery.



Now everytime a new Version of the Graph Modules are released i have to run this Runbook.
You shure can add some logic to detect if the Modules from the PowerShell Gallery are newer and only then update the Modules in Azure Automation. But i leave that to you.

Regards
Andres Bohren