Skip to content

powershell.exe still receives PSModulePath for pwsh when called indirectly #12997

@nickwesselman

Description

@nickwesselman

I know why this is happening given how #11057 was implemented. Is there any sort of workaround, other than explicitly resetting the PSModulePath in the Windows Powershell script?

Steps to reproduce

  1. Set up invocation of powershell.exe in some sort of non-PS tool. In my case, a post-action on a dotnet new template.
    {
      "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
      "args": {
        "executable": "powershell",
        "args": "-File init.ps1 "
      },
      "manualInstructions": [{
         "text": "Run 'init.ps1'"
      }],
      "continueOnError": false,
      "description ": "Initializes something."
    }
  1. Invoke the above from pwsh.

Expected behavior

powershell.exe has correct PSModulePath.

Actual behavior

powershell.exe still has PS7 values in PSModulePath.

C:\path\to\init.ps1 : C:\Users\nwe\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program
files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\Microsoft SQL
Server\140\Tools\PowerShell\Modules\

Environment data


Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions