Import-module "PnP.PowerShell" not working
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
same error on windows server 2016
@AlyaKoni ISE and PS 5.x is not supported anymore - installed PS 7.3 and using VisualStudio Code as Editor worked fine.
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.
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
@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.
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)
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
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
ISE and PowerShell 5 no longer works for PnP. You have to use Visual Studio Code with PowerShell 7.
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: @.***>
Open the PS file in VS code and hit "F5" or select "Run/Start Debugging"
You can insert breakpoints, etc..
You need to install the PowerShell extension in Code. Then just press the play button.
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
Make sure you use PowerShell 7 in your Terminal in Code. Check $PSVersionTable. What kind of error do you get?
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.
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
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.
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"
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>