powershell icon indicating copy to clipboard operation
powershell copied to clipboard

Import-module "PnP.PowerShell" not working

Open AlyaKoni opened this issue 3 years ago • 19 comments

Reporting an Issue

import-module "PnP.PowerShell" not working

Expected behavior

PnP PowerShell should be loaded into actual session

Actual behavior

Not able to load PnP PowerShell into actual session. import-module "PnP.PowerShell" gives following error:

Import-Module : Die Datei oder Assembly "System.Management.Automation, Version=7.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden. In Zeile:1 Zeichen:1 Import-Module "Pnp.PowerShell" CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

Steps to reproduce behavior

Install-Module "PnP.PowerShell" -Scope CurrentUser Import-Module "PnP.PowerShell"

What is the version of the Cmdlet module you are running?

2.1.0 or 2.1.1, both have the issue With 1.12.0 everything works fine

Which operating system/environment are you running PnP PowerShell on?

  • [ X] Windows 10

AlyaKoni avatar Apr 03 '23 22:04 AlyaKoni

same error on windows server 2016

mslucasMMID avatar Apr 04 '23 10:04 mslucasMMID

@AlyaKoni ISE and PS 5.x is not supported anymore - installed PS 7.3 and using VisualStudio Code as Editor worked fine.

SnappyDIY avatar Apr 04 '23 11:04 SnappyDIY

As @SnappyFPV mentioned, you need to install PS 7.2 or later versions. This 2.1.1 release has dropped support for PS 5.1 and ISE.

If you want to keep using PS 5.1 or ISE, you can use the 1.12.0 version. Bug fixes and improvements will only be done on the 2.x releases in the future.

gautamdsheth avatar Apr 04 '23 14:04 gautamdsheth

Same error here. PS 7.3 and using VisualStudio Code as Editor also smae error outside of vscode.

I've also tried the nightly build

LycheeYum avatar Apr 04 '23 15:04 LycheeYum

@AlyaKoni @LycheeYum - Please make sure your PowerShell session is running PS7 regardless of using VSCode or not (VSCode can also run PS5). Works fine on our end with VSCode, Terminal or even on MacOS.

veronicageek avatar Apr 05 '23 19:04 veronicageek

In PS7 the import is working, may now I get if I try to connect:

Line | 1492 | … onnection = Connect-PnPOnline -Url $Url -TenantAdminUrl $TenantAdminU … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not | find or load a specific file. (0x80131621)

AlyaKoni avatar Apr 05 '23 23:04 AlyaKoni

Hi there,

I have installed the latest version of PnP PowerShell 2.3.0 and when I Import-Module PnP.PowerShell with windows PowerShell 7.4 , it's importing fine but when I use windows PowerShell ISE editor and importing Import-Module PnP.PowerShell is throwing following error. I want to debug the script using ISE but unable to do it. I am in windows 11 a surface pro.

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
    

fcbtdoorga avatar Dec 14 '23 03:12 fcbtdoorga

Hi there,

I have installed the latest version of PnP PowerShell 2.3.0 and when I Import-Module PnP.PowerShell with windows PowerShell 7.4 , it's importing fine but when I use windows PowerShell ISE editor and importing Import-Module PnP.PowerShell is throwing following error. I want to debug the script using ISE but unable to do it. I am in windows 11 win a surface pro.

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
    

fcbtdoorga avatar Dec 14 '23 03:12 fcbtdoorga

ISE and PowerShell 5 no longer works for PnP. You have to use Visual Studio Code with PowerShell 7.

AlyaKoni avatar Dec 14 '23 05:12 AlyaKoni

Thank you Konrad,

Can you please provide the guidance of debugging PS Script using VS code?


From: Konrad Brunner @.> Sent: Wednesday, December 13, 2023 11:53 PM To: pnp/powershell @.> Cc: Doorga Shukla @.>; Comment @.> Subject: Re: [pnp/powershell] Import-module "PnP.PowerShell" not working (Issue #2969)

ISE and PowerShell 5 no longer works for PnP. You have to use Visual Studio Code with PowerShell 7.

— Reply to this email directly, view it on GitHubhttps://github.com/pnp/powershell/issues/2969#issuecomment-1855187211, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BEVKRQMO2TBQGCCLQRVS5GTYJKH53AVCNFSM6AAAAAAWR5Q6YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJVGE4DOMRRGE. You are receiving this because you commented.Message ID: @.***>

fcbtdoorga avatar Dec 14 '23 14:12 fcbtdoorga

Open the PS file in VS code and hit "F5" or select "Run/Start Debugging"

You can insert breakpoints, etc..

image

BaronSparky avatar Dec 14 '23 15:12 BaronSparky

You need to install the PowerShell extension in Code. Then just press the play button.

AlyaKoni avatar Dec 14 '23 15:12 AlyaKoni

I've installed Powershell 7.x and Visual Studio Code. I realize based on what is being told here that ISE is no longer supported for PnP 2.3, but i'm also seeing that i'm not able to execute Connect-PnPOnline using Visual Studio Code, after installing the PowerShell extension. So VS Code will not connect to Sharepoint via Connect-PnPonline either? Am I missing a step? Thanks

devops-fan avatar Dec 16 '23 16:12 devops-fan

Make sure you use PowerShell 7 in your Terminal in Code. Check $PSVersionTable. What kind of error do you get?

AlyaKoni avatar Dec 18 '23 06:12 AlyaKoni

Be carefull with powershell versions. I stopped using powershell because some modules do only work with powershell 7 and some doesn't so you end up with a hell of different versions and which does support which.

Programs which do start in powershell but as soon as you want to have a debugger so you start visual code it doesn't work anymore because of different powershell versions.

mslucasMMID avatar Dec 18 '23 07:12 mslucasMMID

In general, all PowerShell modules work in PowerShell 7, but some have to be loaded with special parameters in order to work in PowerShell 7. However, some modules cannot work with other modules. In this case, you will always need a new PowerShell session.

Have a look at my method Install-ModuleIfNotInstalled. This can give you some help when loading modules in PowerShell 7.

https://github.com/AlyaKoni/ALYADO-ADM-Public/blob/master/01_ConfigureEnv.ps1

AlyaKoni avatar Dec 18 '23 08:12 AlyaKoni

Make sure you use PowerShell 7 in your Terminal in Code. Check $PSVersionTable. What kind of error do you get?

$PSVersionTable returns PSversion value of 5.1.22000.2600

After installing the PowerShell extension, I go into Settings | PowerShell Default Version and insert the value "C:\program files\PowerShell\7\7\pwsh.exe, but am informed via log errors that the location could not be found, and get message "Instead using first available installation at c:\windows\system32\windowsPowershell\v1.0\powershell.exe". The pwsh.exe path for PS7 is correct and in existence in my local folder path.

devops-fan avatar Dec 18 '23 15:12 devops-fan

Sure a double 7 in the path? "C:\program files\PowerShell\7\7\pwsh.exe" On my client it is "C:\Program Files\PowerShell\7\pwsh.exe"

AlyaKoni avatar Dec 18 '23 15:12 AlyaKoni

Sure a double 7 in the path? "C:\program files\PowerShell\7\7\pwsh.exe" On my client it is "C:\Program Files\PowerShell\7\pwsh.exe"

Yes, i found it odd too. At the first \7 root, there is another '7' folder, but at the second \7 root I see all the folders and pwsh.exe. Running it opens up a PS 7.4.0 session screen. Path written is "c:\program files\powershell\7\7>

devops-fan avatar Dec 18 '23 15:12 devops-fan