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

Craig Tucker 40 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,256 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,509 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. JAKUBEC Ludovic (Wakers) 5 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 ;)

    1 person found this answer helpful.
    0 comments No comments

  2. Fran Romero 5 Reputation points
    2024-07-31T08:43:04.4033333+00:00

    Hi!

    Same problem here with an Azure Function.

    My function worked successfully until july 16th. I've downgraded ExchangeOnlineManagement module version to 3.5.0 and it works again for me.

    1 person found this answer helpful.
    0 comments No comments

  3. Craig Tucker 40 Reputation points
    2024-07-31T09:04:17.22+00:00

    I ended up downgrading the PowerShell version of the EXO 3.5.1 module and the Azure Runbook to PS v5.1 and that fixed the issue for me.

    It is a shame when PS 7.2 is the recommend version and upgraded modules like EXO aren't simply tested against it. In my case it was the most basic Connect-ExchangeOnline command with a managed identity (something that is becoming more common now) that failed. Someone might need to look at the testing framework

    1 person found this answer helpful.
    0 comments No comments

  4. Sagar Thore 5 Reputation points Microsoft Employee
    2024-08-07T19:11:29.38+00:00

    Hello All,

    After the ExchangeOnlineManagement PowerShell module was released, we noticed that the latest version, 3.5.1, was released on July 11, 2024. Since then, the Azure Function app PowerShell has been failing with the following error. However, when we reverted back to version 3.5.0, it started working fine.

    ERROR: Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].

    https://www.powershellgallery.com/packages/ExchangeOnlineManagement/3.5.1

    Could you please help us determine if there is a problem with this specific latest version?

    1 person found this answer helpful.
    0 comments No comments

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.