microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
687 stars 163 forks source link

Can't run Microsoft Graph & ExchangeOnlineManagement commands together in PowerShell #2850

Closed blackadi closed 2 weeks ago

blackadi commented 1 month ago

Describe the bug

When running Graph commands and ExchangeOnlineManagement commands in a single script it throws an error.

why these 2 modules don’t work together?

Expected behavior

Understand why MS Graph and ExchangeOnlineManagement modules don’t work together?

How to reproduce

running Graph commands and ExchangeOnlineManagement commands in a single script

SDK Version

2.20

Latest version known to work for scenario above?

No response

Known Workarounds

script run in PowerShell 7 but not in in PowerShell 5.

We need PowerShell 5 support since we are using Azure Automation Runbooks which currently support PowerShell 5 runbok only.

Debug output

Click to expand log ``` System.Management.Automation.CommandNotFoundException: The 'Connect-MgGraph' command was found in the module 'Microsoft.Graph.Authentication', but the module could not be loaded. For more information, run 'Import-Module Microsoft.Graph.Authentication'. ---> System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'Azure.Core, Version=1.35.0.0, Culture=neutral, PublicKeyToken=***' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Azure.Core, Version=1.35.0.0, Culture=neutral, PublicKeyToken=***' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.5.0\netFramework\Azure.Core.dll' or one of its dependencies. The system cannot find the file specified. ```

Configuration

No response

Other information

No response

titlerequired commented 1 month ago

In what order do you authenticate in the runbook?

I think I had a similar issue previously but recently this has been working ok for me recently.

blackadi commented 1 month ago

@titlerequired first connecting to MSGraph via this cmdlet Connect-MgGraph -AccessToken ($oAuthReq.access_token | ConvertTo-SecureString -AsPlainText -Force) -NoWelcome then Import-Module ExchangeOnlineManagement

titlerequired commented 1 month ago

You still need to use Connect-ExchangeOnline

alexandair commented 1 month ago

@blackadi

You can use PowerShell 7.2 in Azure Automation. image

yllekz commented 1 month ago

Same issue here (and yes I'm using Connect-ExchangeOnline). Latest version (I jumped to 2.20.0 from 2.16.0) appears to completely break coexistence between these two and should be fixed immediately. I've had to roll back due to this bug.

ildjarnisdead commented 1 month ago

Workaround: First Connect-MgGraph and then Connect-ExchangeOnline works. The other way round does not work.

The actual error occurs while loading Microsoft.Graph.Authentication: Import-Module : Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.5.1\netFramework\Azure.Core.dll' or one of its dependencies. The system cannot find the file specified.

timayabi2020 commented 3 weeks ago

Hello guys. Please update to the latest Microsoft.Graph PowerShell SDK and let us know if you are still experiencing the same issue. A similar issue has been logged here #2803

secretworkpersona commented 3 weeks ago

Latest version (2.21.0) does not resolve the issue for me.

ModuleError

microsoft-github-policy-service[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

yllekz commented 3 weeks ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

bump

k3wio commented 2 weeks ago

@timayabi2020 This issue is still active and present in current versions. Would you like yet another issue opened, or can we have this one reopened as it is not, in fact, completed.

syne0 commented 2 weeks ago

I want to advise that this issue is still occurring for me as well, but not always consistently. It's hard to pin down specific triggers, but I usually end up reinstalling graph and eom.