Microsoft 365 – PnP PowerShell – resolving error – Import-Module : Could not load file or assembly ‘System.Management.Automation, Version=7.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified OR – The ” command was found in the module ‘PnP.PowerShell’, but the module could not be loaded.

fig : Microsoft 365 - PnP PowerShell module - errors
fig : Microsoft 365 - PnP PowerShell module - errors

Hi All,

Greetings for the day!!!

Today new issue and solution 🙂

Background / UseCase

  • I have PowerShell script and performing some operation (adding an item in the SharePoint list)
  • For this purpose I am using PnP PowerShell module and CMDLET – Add-PnPListItem
  • I have prepared the PowerShell and tested on my local environment (Windows 10)
  • I shared with my team member who is executing the script from one of the Windows server (Windows Server 2019 standard)
  • Making sure that PnP PowerShell module is installed
Install-Module PnP.PowerShell

  • When my team member executes the script, getting an error

Error Add-PnPListItem : The ‘Add-PnPListItem‘ command was found in the module ‘PnP.PowerShell‘, but the module could not be loaded. For more information run ‘Import-Module PnP.PowerShell

  • We tried to run the Import-Module and got next error

Import-Module PnP.PowerShell

Error – Import-Module : Could not load file or assembly ‘System.Management.Automation, Version=7.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

fig : Microsoft 365 - PnP PowerShell module - errors
fig : Microsoft 365 – PnP PowerShell module – errors

Solution

  • It found that this issue is with latest version of PnP PowerShell module – 2.1.0 and 2.1.1 – https://github.com/pnp/powershell/issues/2969
  • So after bit googling found following steps to making PnP PowerShell module workable
  • Uninstall all PnP.Powershell versions
Uninstall-Module PnP.PowerShell -AllVersions

  • Set Tls12 protocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

  • Install NuGet
Install-PackageProvider -Name nuget -MinimumVersion 2.8.5.201 -force

  • Install PnP.PowerShell with version 1.12.0

Install-Module -Name "PnP.PowerShell" -RequiredVersion 1.12.0 -Force -AllowClobber

Once all the above steps executed successfully, script executed successfully 🙂

Thanks for reading!!! HAVE A WONDERFUL LEARNING AHEAD !!!

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: