I am having an issue with importing PowerShell modules into a runbook in an automation account. It's a simple script to look at Exchange groups and email a list of matching groups out. It falls down at almost the first step: import-module exchangeonlinemanagement.
I installed the module in the normal way - from the gallery. Although it did import the module, the next command - connect-exchangeonline failed with "System.Management.Automation.RuntimeException: Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment]."
Searching online, it suggested downgrading to version 3.5. I did that using the Azure Automation tab on https://www.powershellgallery.com/packages/ExchangeOnlineManagement/3.5.0
Now, when it reaches the import command it says that there is no module with that name. "The specified module 'ExchangeOnlineManagement' was not loaded because no valid module file was found in any module directory." Searching online doesn't provide any useful suggestions.
The commands work fine in the CLI.
Does anyone have any suggestions?
You need to create a new Runbook using Runtime 5.1.
Funny you should mention this, I just so happened to be researching this yesterday, only to come into work this morning to find a brand new search result! I am posting this less than 10 minutes after figuring out the fix.
Anyways, I did the exact same thing you did, except I troubleshot by using "Get-Module -ListAvailable" in a runtime 5.1 and a 7.2 runbook. The ExchangeOnlineManagement module did not show in 7.2 but did in 5.1.
After confirming the module was showing in the 5.1 runbook, I then tested the actual "Connect-ExchangeOnline" cmd and was able to see that it connected.