question

KathyBlasco-4579 avatar image
0 Votes"
KathyBlasco-4579 asked KantaPrasad27 answered

Getting 'Could not load file or assembly 'Microsoft.Identity.Client, Version=4.21.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or | load a specific file. (0x80131621)' on Connect-PnPOnline

I am trying to run a script in Powershell 7 using PnP.PowerShell version 1.5.0 and I am getting error:

Could not load file or assembly 'Microsoft.Identity.Client, Version=4.21.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or
| load a specific file. (0x80131621)

My connect statement is as follows:

 Connect-PnPOnline -ClientId $env:PnPClientId -Url $URL -Tenant ($env:Tenant + ".onmicrosoft.com") -Thumbprint $env:PnPThumbprint

This seems to be an issue with PowerShell 7 as Windows PowerShell still seems to be working on this same PC using PnP.PowerShell.

Anyone have suggestions on what I might need to change? I have users running scripts in Windows PowerShell so hoping for a uniform statement that works in both PowerShell versions.

windows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm seeing the same behavior in Pnp.PowersShell versions 1.60 and 1.7.0
I had been thinking that it was some sort of conflict with another module like Microsoft.Graph.Authentication, or Az.Accounts, but I get the same error even when those two modules are clearly not imported.

There is an open issue on GitHub related to this: https://github.com/pnp/powershell/issues/1034

0 Votes 0 ·
IanXue-MSFT avatar image
1 Vote"
IanXue-MSFT answered BhavyaChhabra-7813 commented

Hi,

Does updating to the latest version solve the problem? The current version is 1.5.42-nightly.
https://www.powershellgallery.com/packages/PnP.PowerShell

If the problem is not solved you can report it over here
https://github.com/pnp/powershell/issues

As the module works with Windows PowerShell, you may also try loading the PnP.Powershell module using the Windows PowerShell Compatibility feature.

 Import-Module -Name PnP.Powershell -UseWindowsPowerShell

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Ian. It is working with the -UseWindowsPowershell switch.

It is a workaround though and it should really work with Powershell 7 as well.

0 Votes 0 ·
KantaPrasad27 avatar image
0 Votes"
KantaPrasad27 answered

I removed Powershell 7 and it started working fine with PS 5.1.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.