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.

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.
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 !!!
You must be logged in to post a comment.