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

Kathy Blasco 101 Reputation points
2021-05-13T19:02:40.037+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,486 Reputation points Microsoft Vendor
    2021-05-14T06:51:43.653+00:00

    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.

    2 people found this answer helpful.

  2. Kanta Prasad 26 Reputation points
    2021-10-27T08:22:53.983+00:00

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

    0 comments No comments

  3. Sean Barton Boltman 1 Reputation point
    2022-10-03T14:48:45.883+00:00

    247054-image.png