Microsoft 365 – PnP PowerShell – resolving error – Import-Module : Could not load file or assembly ‘System.Management.Automation, Version=188.8.131.52, 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.
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
- 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
Error – Import-Module : Could not load file or assembly ‘System.Management.Automation, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
- 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 220.127.116.11 -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 log in to post a comment.