I'm unable to run PnP PowerShell commands using PowerShell ISE in administrative mode. Getting following error
PS C:\WINDOWS\system32> Import-Module PnP.PowerShell
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.
At line:1 char:1
+ Import-Module PnP.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
My PowerShell ISE details
PS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\WINDOWS\system32> get-host|Select-Object
Name : Windows PowerShell ISE Host
Version : 5.1.19041.1
InstanceId : d91d81d9-be20-492f-be62-f5ea45de0765
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : FalseRunspace : System.Management.Automation.Runspaces.LocalRunspace
Please help me to solve this error. Thanks in advance
My error is similar. I just updated to 2.1.1. I was not having an issue prior to the upgrade. My error:
Import-Module -Name PnP.PowerShell -Debug -Force
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\2.1.1\PnP.PowerShell.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\2.1.1\PnP.PowerShell.Format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module PnP.PowerShell.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\2.1.1\Core\PnP.PowerShell.dll'.
Import-Module : Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
At line:1 char:1
+ Import-Module -Name PnP.PowerShell -Debug -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
What version of System.Management.Automation is installed on your machine?
The version on my machine Windows 10, PowerShell 5.1) (without any PNP packages installed) is 6.x.x.x.
Your module is looking for version 7.2.0.0.
I can see System.Management.Automation. but still not sure how to fix this issue
C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
I started seeing this error after setting up a VDI at a customer site. After comparing my setup with my customer's setup, I can see that he had version 1.12.0 and I had 2.1.1.
Here is what I did to resolve it:
Uninstalled the module
Rebooted (not sure if this is necessary)
Installed a specific version of the module: Install-Module -Name PnP.PowerShell -RequiredVersion 1.12.0
and I am working again now
Hi Risbud,
Thanks for your instruction. It works for the Import-Module PnP.Powershell. Due to Microsoft PowerShell and Window's PowerShell change. Bunch of my Ps1 files do not work any more. I have spent time to review the PowerShell. It seems that Microsoft has made PowerShell more confusing and becoming a useless tool. Check the Exchange online PowerShell, SharePoint Online PowerShell, Azure PowerShell, these are pieces of garbage! A disaster! All of these PowerShell does not even cover complete set of functionalities. Looked at their reference, it's just a small set of functions.
Thank you Risbud!
George
After installing Version 2.1.1 of PnP Powershell, i faced the same issue. It looks like this version has some compatibility issue with Powershell ISE version 5.
Below are the steps that i used to overcome this issue as a workaround.
Uninstalled all versions of PnP Module
Uninstall-Module PnP.PowerShell -AllVersions
Install nuget package
Install-PackageProvider -Name nuget -MinimumVersion 2.8.5.201 -force
Installed version 1.12.0 for PnP Powershell Module.
Install-Module -Name "PnP.PowerShell" -RequiredVersion 1.12.0 -Force -AllowClobber
Now i am able to import the PnP Module without any issues.
Hi @H Risbud ,
I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.
By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:
[Import-Module : Could not load file or assembly 'System.Management.Automation]
Issue Symptom:
unable to run PnP PowerShell commands using PowerShell ISE in administrative mode. Getting following 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:
Uninstall all versions and then install correct 1.12.0 version. Newer version PnP PowerShell 2.1.1 has issues #1. This issue happened with newer version PnP PowerShell 2.1.1.
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
You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!
This worked for me. I initially continued to have issues until I figured this out...
If you are using PS 5.1, YES, you need to have PnP.PowerShell 1.12.0 installed.
Yes, you CAN have this installed alongside 2.1.1. The requirement is that you have to Import the correct version in your 5.1 scripts. If you don't, it will load the latest version and you'll continue to get the error.
You can do this by putting this at the top of your scripts running in PS 5.1 :
Import-Module pnp.powershell -RequiredVersion 1.12.0
Basic stuff, unless you don't read the fine print - like me.
Solved with this process - Uninstall all versions and then install correct 1.12.0 version. Newer version PnP PowerShell 2.1.1 has issues
#1. This issue happened with newer version PnP PowerShell 2.1.1. So uninstall all PnP.Powershell versions. No need to reboot machine
Uninstall-Module PnP.PowerShell -AllVersions
#2. Set Tls12 protocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#this setting already present
[Net.ServicePointManager]::SecurityProtocol
#3. Install NuGet
Install-PackageProvider -Name nuget -MinimumVersion 2.8.5.201 -force
#4. Install PnP.PowerShell with version 1.12.0
Install-Module -Name "PnP.PowerShell" -RequiredVersion 1.12.0 -Force -AllowClobber
I feel being lured into working with the PnP version 2.1.1 for use by the latest PS7.3.4 and struggling to get the simplest functions to deliver.
Is the released version tested at all ? Or is it left for the community to test ?
Also the documentation lacks proper definitions and details on every output for every API (ie Method), and this goes also for general SharePoint API's as well.
Can anyone point to a stable' working PnP.PowerShell module for PS7 ?
So I felt the need to come in here and provide some extra information as I think the BIGGER problem is not visible for everyone here.
Installing the Older version of PNP.Powershell is actually the wrong direction as I found out yesterday. It boils down to the Powershell version you are running on your computer.
With this important point noted, here is some extra guidance.
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7.3
When reading the above link from Microsoft, they correctly tell us that Powershell 7 must be installed and it will NOT overwrite Powershell 5. The two versions run side-by-side on your computer. When you open your Powershell command, be sure to run the "$PSVersionTable.PSVersion" to see what version you are running as the EXEs are NOT the same! You have to look for the new installation in your Start menu to run the correct version or go directly to the install path to run the correct EXE.
Now what about the BIG question... Those of us who have been developing scripts for making our lives easier and might have been using the ISE. Yup, the ISE does not run version 7. We must go install https://code.visualstudio.com/ in order to get to that same usage. (This is covered in the above link as well.)
I hope all of this helps!
P.S. Thank you Microsoft for making things complicated... 😂😂😂
If version 2.1.1 is really only intended for powershell 7, why does the following popup in windows powershell:
WARNING:
A newer version of PnP PowerShell is available: 2.1.1.
It was so simple my problem.... Well I used scripts that call powershell commands using bypass, so, my error was that there I was calling with the command "powershell" at the start of the line when now with Powershell 7 has to be "pwsh". Changing this my scripts doesn't show up more problems and it work as expected. I guess it would be nice that through open Powershell 7 the scripts could use the old poweshell call... But for some reason you have to rewrite your own script in order to use now Powershell 7.