Skip to content

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

@HeyItsGilbert

Description

@HeyItsGilbert

Prerequisites

Steps to reproduce

This is a dupe of #12997 which was closed.

  1. Set up invocation of powershell.exe in some sort of non-PS tool.
  2. Example below of a bat with New-Guid (different between PS versions)
  3. Invoke the bat from pwsh.

example.bat

echo %psmodulepath%

powershell.exe "$env:PSModulePath -split ';' | Select-String 'PowerShell'; New-Guid"

Expected behavior

Powershell.exe instance does not contain `C:\Program Files\PowerShell\7`

Actual behavior

Powershell.exe still has PS7 values in PSModulePath and New-Guid throws an error. This is in a pwsh.exe window.

PS C:\Users\gsanchez\temp> .\example.bat

C:\Users\gsanchez\temp>echo C:\Users\gsanchez\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)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\
C:\Users\gsanchez\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)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\

C:\Users\gsanchez\temp>powershell.exe "$env:PSModulePath -split ';' | Select-String 'PowerShell'; New-Guid"

C:\Users\gsanchez\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
New-Guid : The term 'New-Guid' 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.
At line:1 char:60
+ $env:PSModulePath -split ';' | Select-String 'PowerShell'; New-Guid
+                                                            ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Guid:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Error details

New-Guid : The term 'New-Guid' 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.
At line:1 char:52
+ $env:Path -split ';' | Select-String 'PowerShell'; New-Guid
+                                                    ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Guid:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.10
PSEdition                      Core
GitCommitId                    7.3.10
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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions