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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading