PowerShell Universal version: 3.7.10
Environment: PowerShell v. 7.3.1
Server OS: 2022
Have anyone had any issues with the ExchangeOnlineManagement module, that it throws the error: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.44.0.0, Culture=neutral
From PSU dashboards or scripts I can import the ExchangeOnlineManagement module, but when I try and connect with Connect-ExchangeOnline I receive the above error.
When I try from a normal PS session directly on the server everything works as expected.
Also if I in PSU switch to the PS 5.1 environment and run the script, it works and I can connect.
I have tried:
Reinstall the ExchangeOnlineManagement module.
Remove the Microsoft.Graph module (have read that could interfere).
I would recommend against using that module in PSU. Since the REST-based cmdlets have been introduced in EXO, you can achieve the exact same result by talking directly to https://outlook.office365.com/adminapi/beta/{tenant ID}/InvokeCommand with less footprint and fewer issues in general. POST JSON payload like "{"CmdletInput":{"CmdletName":"Get-MobileDevice","Parameters":{"ResultSize":"Unlimited"}}} You can set “X-ResposeFormat” header to “clixml” have the output conveniently sent to you as natively serialized Powershell.
Egor would love to avoid using the module and entirely use REST calls to ExO. But from what I have read, and is shown in the URL, it is still in a beta phase. That’s why I haven’t considered using it.
But have you used it a lot and can confirm it is stable to use in production?
@Tbmoeller This is the very same endpoint the module is hitting. You can grab Fiddler and confirm yourself. So its as stable as using EXO module (assuming your code is sane).
The same thing applies to other Graph-based modules (azureadpreview, mg-*, az) tbh. I learned the hard way that some modules leak memory, some don’t maintain session while running inside PSU, so I just rolled my own very lightweight Invoke-GraphRequest function and everything is good so far (I still rely on MSAL.PS to get tokens as I use certificate-based auth and implementing it from scratch is a bit beyond my powershell skills).
Hi. I don’t believe it’s documented officially, as technically it’s an internal API, but Vasil Michev wrote a nice write up on this – (Ab)using the REST API endpoints behind the new ExO cmdlets | Blog (also check the comments section, some very solid hints there)
Upd: The link is not exactly accurate, it’s more for new EXO- cmdlets. Since it’s somewhat relevant and definitely helpful, I’m keeping it. But please see this Exchange Online PowerShell module gets rid of the WinRM dependence | Blog for actual examples on using InvokeCommand endpoint.
@adam have same issue with the ExchangeOnline module. Though in my case the issue is “System.IdentityModel.Tokens.Jwt” which have a version mismatch.
The module expects version 6.22.1.0 but PSU has version 6.22.0.0.
Full error:
Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.22.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
To get around this, I downloaded the latest PS7, created a new environment with it and then it worked.
Though I have seen examples of another issue with “System.IdentityModel.Tokens.Jwt” where, if a module includes an older version, and that version has been loaded, then the newer version wont be loaded when needed.
It will be in the 3.7.12 release. I don’t have a good workaround for this for the time being but we should be able to get that release out this week.
This change is already in the nightly builds if you want to try them out.
Wondering if this is still an active issue. I am doing the same thing, cert auth exchange connection and getting: Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.12.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)