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

PowerShell Notebook - Can't import Pester #136

Closed
SQLDBAWithABeard opened this issue Feb 7, 2020 · 11 comments · Fixed by #189
Closed

PowerShell Notebook - Can't import Pester #136

SQLDBAWithABeard opened this issue Feb 7, 2020 · 11 comments · Fixed by #189
Assignees
Labels

Comments

@SQLDBAWithABeard
Copy link

@SQLDBAWithABeard SQLDBAWithABeard commented Feb 7, 2020

Describe the bug

I tried to run one of my Azure Data Studio PowerShell notebooks into a PowerShell Notebook using .NET Jupyter. It worked fine until I tried to import my dbachecks module which uses Pester. I then created a new Notebook and tried to just run some Pester

The error I receive is

Describe: The 'Describe' command was found in the module 'Pester', but the module could not be loaded. For more information, run 'Import-Module Pester'.

When I try to just import Pester by itself using any of my available versions even 3.4.0 I get

Get-Command: C:\Users\mrrob\Documents\PowerShell\Modules\pester\4.9.0\Pester.psm1
Line |
  94 |     $script:SafeCommands['Get-CimInstance'] = Get-Command -Name Get-CimInstance -Module CimCmdlets @safeCommandLookupParameters

     |                                               ^ The term 'Get-CimInstance' is not recognized as the name of a
     | cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
     | verify that the path is correct and try again.
Import-Module: The module to process 'Pester.psm1', listed in field 'ModuleToProcess/RootModule' of module manifest 'C:\Users\mrrob\Documents\PowerShell\Modules\pester\4.9.0\pester.psd1' was not processed because no valid module was found in any module directory.

output of Get-Module Pester -ListAvailable

    Directory: C:\Users\mrrob\Documents\PowerShell\Modules
ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.9.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     4.8.1                 Pester                              Desk      {Describe, Context, It, Should…}
    Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.8.1                 Pester                              Desk      {Describe, Context, It, Should…}
Script     3.4.0                 Pester                              Desk      {Describe, Context, It, Should…}

Did this error occur while using dotnet interactive?

  • [ X] .NET Jupyter Notebook

Screenshots

If applicable, add screenshots to help explain your problem.

Please complete the following:

  • OS
    • [X ] Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • [X ] Chrome
    • [ X] Edge
    • Safari
  • Frontend
    • Jupyter notebook
    • [X ] Jupyter lab
    • nteract
@SQLDBAWithABeard

This comment has been minimized.

Copy link
Author

@SQLDBAWithABeard SQLDBAWithABeard commented Feb 7, 2020

@nohwnd

This comment has been minimized.

Copy link
Member

@nohwnd nohwnd commented Feb 7, 2020

@wsmelton I am seeing, I see it in your screenshot as well, do you have any fix for that?

Import-Module: The module to process 'Pester.psm1', listed in field 
'ModuleToProcess/RootModule' of module manifest 
'...\Documents\PowerShell\Modules\pester\4.9.0\pester.psd1' 
was not processed because no valid module was found in any 
module directory.
@wsmelton

This comment has been minimized.

Copy link

@wsmelton wsmelton commented Feb 7, 2020

I go by this, but then checking the Exported Commands and it is there:
image

image

@wsmelton

This comment has been minimized.

Copy link

@wsmelton wsmelton commented Feb 7, 2020

...but even changing the psm1 to this line of the module it still fails, so I think the implicit remoting is the issue:

$script:SafeCommands['Get-CimInstance'] = Get-Command -Name Get-CimInstance -Module CimCmdlets -CommandType Cmdlet -ErrorAction Stop -All
@wsmelton

This comment has been minimized.

Copy link

@wsmelton wsmelton commented Feb 7, 2020

This is indeed the remoting issue because I just caught that the kernel is importing the Windows PowerShell version of the CimCmdlets module (note the version is 1.0.0.0 which is Windows release). The version matched to PowerShell 7 is version 7.0.0.0

image

@daxian-dbw

This comment has been minimized.

Copy link
Contributor

@daxian-dbw daxian-dbw commented Feb 7, 2020

@wsmelton Thanks for reporting this! Yes, it was the CimCmdlets module from the system32 module path that got imported (via the WinCompat feature added in PS7). This is because currently the PS kernel don't ship all the built-in modules along with it ...
The built-in modules are not published anywhere and are platform specific, it's hard for an application that host powershell to ship them along. We have the issue PowerShell/PowerShell#11783 to track this work.

@wsmelton

This comment has been minimized.

Copy link

@wsmelton wsmelton commented Feb 7, 2020

@daxian-dbw maybe I'm missing something...

While it is true that not all modules are going to be shipped with PowerShell, CIM cmdlets are not one of them, they are indeed shipped with the versions of PowerShell (both 6 and 7). You can find the DLL, Microsoft.Management.Infrastructure.CimCmdlets.dll, located in the root directory of each version of PowerShell:

image

@daxian-dbw

This comment has been minimized.

Copy link
Contributor

@daxian-dbw daxian-dbw commented Feb 7, 2020

While it is true that not all modules are going to be shipped with PowerShell, CIM cmdlets are not one of them, they are indeed shipped with the versions of PowerShell (both 6 and 7).

Yes, indeed.
What I meant is that not all built-in modules (literally the module folders) that come with PowerShell (6/7) out-of-box are currently shipped along with the PowerShell Jupyter kernel.

The following 7 modules are what the PowerShell Jupyter kernel currently ship, and we only have the Utility and Management built-in modules, no CimCmdlets.
We are working on getting this fixed.

image

@SQLDBAWithABeard

This comment has been minimized.

Copy link
Author

@SQLDBAWithABeard SQLDBAWithABeard commented Feb 21, 2020

@SQLDBAWithABeard

This comment has been minimized.

Copy link
Author

@SQLDBAWithABeard SQLDBAWithABeard commented Feb 22, 2020

That was a mistake that everyone at PowerShell Saturday Hamburg saw!!

Please re-open

@daxian-dbw

This comment has been minimized.

Copy link
Contributor

@daxian-dbw daxian-dbw commented Feb 24, 2020

@SQLDBAWithABeard The PR #189 brought in CimCmdlets and other built-in modules for the PowerShell kernel, so importing Pester should work fine now.

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

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.