Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import-module "PnP.PowerShell" not working #2969

Closed
AlyaKoni opened this issue Apr 3, 2023 · 19 comments
Closed

Import-module "PnP.PowerShell" not working #2969

AlyaKoni opened this issue Apr 3, 2023 · 19 comments

Comments

@AlyaKoni
Copy link

AlyaKoni commented Apr 3, 2023

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 AlyaKoni added the bug Something isn't working label Apr 3, 2023
@mslucasMMID
Copy link

same error on windows server 2016

@SnappyFPV
Copy link

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

@gautamdsheth
Copy link
Collaborator

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.

@LycheeYum
Copy link

LycheeYum commented Apr 4, 2023

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

@veronicageek veronicageek removed the bug Something isn't working label Apr 4, 2023
@veronicageek veronicageek changed the title [BUG] Import-module "PnP.PowerShell" not working Apr 4, 2023
@veronicageek
Copy link
Collaborator

@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.

@AlyaKoni
Copy link
Author

AlyaKoni commented Apr 5, 2023

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)

@fcbtdoorga
Copy link

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
Copy link

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
    

@AlyaKoni
Copy link
Author

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

@fcbtdoorga
Copy link

fcbtdoorga commented Dec 14, 2023 via email

@BaronSparky
Copy link
Contributor

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

You can insert breakpoints, etc..

image

@AlyaKoni
Copy link
Author

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

@devops-fan
Copy link

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

@AlyaKoni
Copy link
Author

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

@mslucasMMID
Copy link

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.

@AlyaKoni
Copy link
Author

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

@devops-fan
Copy link

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.

@AlyaKoni
Copy link
Author

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"

@devops-fan
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants