Connect-ExchangeOnline in Azure Automation account gives Unable to find type (EXO 3.5.1 PS7.2)

Craig Tucker 20 Reputation points
2024-07-25T10:20:56.2033333+00:00

I have setup an Azure Automation account and loaded the EXO 3.5.1 module along with PackageManagement V1.4.8.1 and PowerShellGet v2.2.5. I open a new PowerShell runbook and just posted a Connect-ExchangeOnline -ManagedIdentity - Organisation "xyz.onmicrosoft.com" command. Saved and tested and got an error

System.Management.Automation.RuntimeException: Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].
   at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
   at System.Management.Automation.Language.Compiler.GetAttribute(TypeConstraintAst typeConstraintAst)
   at System.Management.Automation.Language.TypeConstraintAst.GetAttribute()
   at System.Management.Automation.Language.Compiler.GetRuntimeDefinedParameter(ParameterAst parameterAst, Boolean& customParameterSet, Boolean& usesCmdletBinding)
   at System.Management.Automation.Language.Compiler.GetParameterMetaData(ReadOnlyCollection`1 parameters, Boolean automaticPositions, Boolean& usesCmdletBinding)
   at System.Management.Automation.Language.FunctionDefinitionAst.System.Management.Automation.Language.IParameterMetadataProvider.GetParameterMetadata(Boolean automaticPositions, Boolean& usesCmdletBinding)
   at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()
   at System.Management.Automation.CompiledScriptBlockData.Compile(Boolean optimized)
   at System.Management.Automation.ScriptBlock.Compile(Boolean optimized)
   at System.Management.Automation.PSScriptCmdlet..ctor(ScriptBlock scriptBlock, Boolean useNewScope, Boolean fromScriptFile, ExecutionContext context)
   at System.Management.Automation.CommandProcessor.Init(IScriptCommandInfo scriptCommandInfo)
   at System.Management.Automation.CommandProcessor..ctor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, Boolean useLocalScope, Boolean fromScriptFile, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.GetScriptAsCmdletProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, Boolean useNewScope, Boolean fromScriptFile, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(FunctionInfo functionInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

The Automation account managed identity was given the necessary permissions to connect to the Exchange Online PowerShell and the Exchange Administrator role following https://learn.microsoft.com/en-au/powershell/exchange/connect-exo-powershell-managed-identity?view=exchange-ps&WT.mc_id=M365-MVP-9501

Have repeated the exercise with a brand new RG, AA and RB with same result

I notice that other users have been reporting the same issue in the last few days on Reddit

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,198 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,337 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. JAKUBEC Ludovic (Wakers) 0 Reputation points
    2024-07-29T08:21:33.1166667+00:00

    Hi,

    Same issue with Azure Functions.

    If you downgrade the version of the ExchangeOnline Powershell module (3.4 or 3.5), it will work again ;)

    0 comments No comments