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.
Then I thought it might be helpful if I switch to Windows PowerShell ISE to debug what is happening. And it showed me more details like the commands I was searching for were not included in the module.
Solution:
After some digging, I found out that with this issue happened with the newer version PnP PowerShell 2.1.1. We need to forcefully install 1.12.0 version.
- Uninstall all versions and then install correct 1.12.0 version. Use below command to remove all the version:
Uninstall-Module PNP.PowerShell -AllVersions
- Set Tls12 protocol with below command
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- Install NuGet using below command
Install-PackageProvider -Name nuget -MinimumVersion 2.8.5.201 -force
- Install PnP.PowerShell with version 1.12.0 using below command
Install-Module -Name "PnP.PowerShell" -RequiredVersion 1.12.0 -Force –AllowClobber
Reference: