Connect-EXOPSSession Unavailable in Azure Functions
See original GitHub issueAzure CloudShell has been offering for some time now the ability of using Connect-EXOPSSession, without importing any module manually.
However trying to use the Connect-EXOPSSession cmdlet within an Azure Function results in the error below. Is there anything extra required to have this working - along with other Exchange Online cmdlets - or it’s simply not supported for now ?
2020-07-29T20:15:03Z [Error] ERROR: The term 'Connect-EXOPSSession' 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.
Exception :
Type : System.Management.Automation.CommandNotFoundException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : The term 'Connect-EXOPSSession' 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.
HResult : -2146233087
TargetObject : Connect-EXOPSSession
CategoryInfo : ObjectNotFound: (Connect-EXOPSSession:String) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo :
ScriptLineNumber : 12
OffsetInLine : 1
HistoryId : 1
ScriptName : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1
Line : Connect-EXOPSSession
PositionMessage : At D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1:12 char:1
+ Connect-EXOPSSession
+ ~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage
PSCommandPath : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1
InvocationName : Connect-EXOPSSession
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1: line 12
CommandName : Connect-EXOPSSession
TargetSite :
Name : LookupCommandInfo
DeclaringType : System.Management.Automation.CommandDiscovery, System.Management.Automation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
StackTrace :
at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
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)
Message : The term 'Connect-EXOPSSession' 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.
Data : System.Collections.ListDictionaryInternal
Source : System.Management.Automation
HResult : -2146233087
TargetObject : Connect-EXOPSSession
CategoryInfo : ObjectNotFound: (Connect-EXOPSSession:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo :
ScriptLineNumber : 12
OffsetInLine : 1
HistoryId : 1
ScriptName : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1
Line : Connect-EXOPSSession
PositionMessage : At D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1:12 char:1
+ Connect-EXOPSSession
+ ~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage
PSCommandPath : D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1
InvocationName : Connect-EXOPSSession
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\RetrieveO365PhotosAndInjectToStorage\run.ps1: line 12
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to connect to Exchange online in Azure function
1 Answer 1 ... This cmdlet connects to Exchange Online in an unattended scripting scenario using a certificate thumbprint. From this Microsoft ......
Read more >Cannot connect Exchange online with Powershell
Hello. I have a problem to connect to Exchange online with a global admin account (MFA enabled). Here are the errors I get:...
Read more >TSL version issue in Azure function
I have an azure function that connects to client tenants azure. It works for almost all tenants but a few where I get...
Read more >Could not load type 'System.Security.Cryptography. ...
Trying to use azure functions to run an Exchange update powershell script. When using this command: Connect-ExchangeOnline -AppId $appId ...
Read more >Connect to Exchange Online PowerShell
To connect to Exchange Online PowerShell for automation, see App-only authentication for unattended scripts and Use Azure managed identities to connect to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @luckerby ,
Here is the potential workaround for the V2 module which might have some dependencies that are not Core CLR compliant.
Install PowerShell Core 7 locally. Install module + dependencies (if any). Then, import the module in
PowerShell 7
using the-UseWindowsPowerShell
flag, e.g.,Import-Module <moduleName> -UseWindowsPowerShell
If the module imports with no errors, run the commands you need for your script. If everything works correctly, then it is possible that it will run in the Azure Functions service.To install
PowerShell 7
, go to https://github.com/PowerShell/PowerShell/releases/, or just run this in PowerShell:iex "& { $(irm 'https://aka.ms/install-powershell.ps1')} -UseMSI"
If (1) did not work, try to reach out to the team that owns the module to see if there are any plans to make the module + dependencies Core CLR complaint.
Alternatively, you could try to use Functions V1 + PowerShell experimental support (for Windows PowerShell 5.1). Please keep in mind that this is just experimental support and there are no plans to improve this offering.
For those still experiencing this issue, this might do the trick