Skip to content

Issue importing PKI module when using pwsh -command #21319

@jalkire

Description

@jalkire

Prerequisites

Steps to reproduce

  1. Install PowerShell 7.4.1 on Windows
  2. Attempt to use pwsh -command to use the PKI module (for example > pwsh -c "Import-Module PKI")

Note that the import works fine when run directly (> Import-Module PKI). pwsh -c "Import-Module PKI" also works fine in PowerShell 7.3.1. I was able to reproduce the same behavior in an Azure DevOps pipeline as well (not public), so I don't think it has to do with my machine.

I was able to work around this by setting the $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'), like
pwsh -c { $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') ; Import-Module PKI }

I realize PKI is a Windows PowerShell module, but the above scenario was working in PowerShell Core until 7.4.1.

Expected behavior

PS> pwsh -c "Import-Module PKI"
* silently succeeds, just like when running:
PS> Import-Module PKI

Actual behavior

PS> pwsh -c "Import-Module PKI"
Import-Module: The module to process 'Microsoft.CertificateServices.PKIClient.Cmdlets', listed in field 'NestedModules' of module manifest 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\PKI\PKI.psd1' was not processed because no valid module was found in any module directory.

Error details

no output

Environment data

Name Value


PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visuals

Screenshot showing that the pwsh -c "Import-Module PKI" command fails but simply running Import-Module PKI works

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.4-regressionRegression in 7.4In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the product

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions