Fix conflicts between PnP.PowerShell and Microsoft.Graph.Authentication module

German post was automatically translated by DeepL and manually reviewed

If someone uses the two PowerShell modules PnP.PowerShell and Microsoft.Graph.Authentication in scripts, conflicts can occur repeatedly.

There are currently two known and often discussed conflicts. They are due to outdated DLL versions in the PnP.PowerShell module. And no, the order in which the modules are loaded does not play a role in my cases. In my case, I load Microsoft.Graph.Authentication and do not load the PnP.PowerShell module.

Conflict 1

Error “Microsoft.Graph.Core, Version=1.25.1.0” > I described the cause and solution in February; also see the GitHub discussion.


Conflict 2

Error “Could not load type ‘Microsoft.Identity.Client.BaseAbstractApplicationBuilder`1’ from assembly ‘Microsoft.Identity.Client, Version=4.50.0.0”

PowerShell

Similar to conflict 1, it loads an outdated file from the PnP.PowerShell module. In practice, Connect-MgGraph should use the file from its own module.

PowerShell
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location | where FullName -like "Microsoft.Identity.Client,*"

PowerShell

Checking the Microsoft.Identity.Client.dll file in the PnP.PowerShell module confirms the old version.

Veraltete Microsoft.Identity.Client.dll
Outdated Microsoft.Identity.Client.dll

The problem is described in GitHub. As a solution, someone mentions replacing the old DLL in the PnP.PowerShell module with the one from Microsoft.Graph.Authentication. Once the file has been replaced, Connect-MgGraph works again. Deleting the file is not advisable in this conflict. PnP.PowerShell needs the file.

I wrote the PowerShell script Resolve-TAPnPPowerShellConflicts for both conflicts. The script executes the mentioned solutions for both conflicts. Note the information in the command and my documentation.

  • For conflict 1, it deletes the file Microsoft.Graph.Core.dll from the PnP.PowerShell Directory. Connect-MgGraph then loads the correct DLL.
  • For conflict 2, it overwrites Microsoft.Identity.Client.dll in the PnP.PowerShell Directory with the version from Microsoft.Graph.Authentication. Connect-MgGraph can then establish the connection without error.
Microsoft.Identity.Client.dll wurde ersetzt
Microsoft.Identity.Client.dll has been replaced

Please note that after an update of the PnP.PowerShell module, the script must be executed again.
If unexpected issues occur with PnP.PowerShell due to the two changes, the issue can be solved easily: Update-Module PnP.PowerShell -Force
An update overwrites everything in the current PnP.PowerShell directory.

Share
Avatar photo

Topedia Translation Bot

Translation Bot is an automated service to translate posts from German to English. All posts published by the Translation Bot are automatically translated via DeepL and reviewed manually.

Leave a Reply

Your email address will not be published. Required fields are marked *