Fix 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.” with the usage of PnP commands
When I tried to use PnP PowerShell with just the basic connection, I've got errors immediately with Windows 11. Why it happened - I don't know, but I do how to fix it.
The solution consists of 4 steps:
1. Uninstall all versions PnP PowerShell
Uninstall-Module PnP.PowerShell -AllVersions
2. Set Tls12 protocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3. Install Nuget
Install-PackageProvider -Name nuget -MinimumVersion 2.8.5.201 -force
The result is smth like this:
Name Version Source Summary
---- ------- ------ -------
nuget 2.8.5.208 https://onege... NuGet provider for the OneGet meta-package manager
4. Install PnP.PowerShell
Install-Module -Name "PnP.PowerShell" -RequiredVersion 1.12.0 -Force -AllowClobber