Import-Module : Could not load file or assembly 'System.Management.Automation

H Risbud 246 Reputation points
2023-04-04T17:22:30.65+00:00

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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,581 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,557 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 26,876 Reputation points Microsoft Vendor
    2023-04-05T02:35:54.4933333+00:00

    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:

    1. 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.
    2. Set Tls12 protocol [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    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

    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!

    38 people found this answer helpful.

6 additional answers

Sort by: Most helpful
  1. WP 5 Reputation points
    2023-07-14T10:14:58.21+00:00

    This is unacceptable and should have been fixed straight away or at least with the first update after this problem appeared. It is not supposed to be a game of "match the right version".

    1 person found this answer helpful.
    0 comments No comments

  2. Matt Derosia 0 Reputation points
    2023-05-18T15:25:36.8433333+00:00

    User's image

    I am attempting to run PNP Powershell in PS v5 and doesnt mention anything about needing to migrate to v7.