$env:PSModulePath gets "C:\Program Files (x86)\WindowsPowerShell\Modules" added when running script in Visual Studio 2019 PowerShell Project

Issue #195 resolved
Anthony Missico created an issue

After running a script in Visual Studio 2019 within a PowerShell Project, the path "C:\Program Files (x86)\WindowsPowerShell\Modules" is added to $env:PSModulePath.

The behavior below is not seen in Visual Studio Code or PowerShell ISE or Visual Studio 2019 without a PowerShell Project loaded.

Started VS without PowerShell Interactive opened.

Opened Interactive, ran $env:PSModulePath.split(";")

PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE> $env:PSModulePath.split(";")
C:\Users\{userName}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Microsoft Security Client\MpProvider
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

Opened PowerShell project

Ran $env:PSModulePath.split(";") from Interactive

PS A:\Ws1\Personal\amissico\EpicDevOpsService.Wip> $env:PSModulePath.split(";")
C:\Users\{userName}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Microsoft Security Client\MpProvider
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

Executed ‘Copy-Module.ps1’ script.

This script uses “$sModulePath = $env:PSModulePath.split(";")[1]”

PS A:\Ws1\Personal\amissico\EpicDevOpsService.Wip> {removed…}\Modules\Copy-Module.ps1
[VERBOSE] Performing the operation "Remove File" on target "C:\Program Files (x86)\WindowsPowerShell\Modules\{companyName}\Format-XML.ps1".

Notice that $sModulePath is “C:\Program Files (x86)\WindowsPowerShell\Modules”

Ran $env:PSModulePath.split(";") from Interactive

PS A:\Ws1\Personal\amissico\EpicDevOpsService.Wip> $env:PSModulePath.split(";")
C:\Users\PHMIT.amissico\Documents\WindowsPowerShell\Modules
C:\Program Files (x86)\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Microsoft Security Client\MpProvider
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

Name                           Value                                                                                                           
----                           -----                                                                                                           
PSVersion                      5.1.14409.1018                                                                                                  
PSEdition                      Desktop                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                         
BuildVersion                   10.0.14409.1018                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                 
WSManStackVersion              3.0                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                             
SerializationVersion           1.1.0.1      

4.9.4 per "Manage Extensions"

Name             : PowerShell Tools for Visual Studio Host
Version          : 4.9.0.0

Name                   : Microsoft Visual Studio
FileName               : C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe
Version                : 16.0

4.7.2 is installed. Validated against registry and installation package.

Microsoft Visual Studio Enterprise 2019
Version 16.3.2
VisualStudio.16.Release/16.3.2+29326.143
Microsoft .NET Framework
Version 4.7.03062

Installed Version: Enterprise

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASP.NET and Web Tools 2019   16.3.283.64955
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   16.3.283.64955
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.3.283.64955
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.4.2000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.3.283.64955
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.4.2000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

ILSpy.AddIn   1.0
Integration of the ILSpy Decompiler into Visual Studio.

Markdown Editor   1.12.236
A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure HDInsight Azure Node   2.4.2000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.4.2000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.4.2000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 - v2.9.20816.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.0.83+gbc8a4b23ec
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager   5.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

PowerShell Pro Tools for Visual Studio   1.0
A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio.

Productivity Power Tools 2017/2019   16.0
Installs the individual extensions of Productivity Power Tools 2017/2019

Project   1.0
Information about my package

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

RegexTester   1.0
This is regular extension tester.

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Analysis Services   15.0.1528.0
Microsoft SQL Server Analysis Services Designer 
Version 15.0.1528.0

SQL Server Data Tools   16.0.61908.27190
Microsoft SQL Server Data Tools

SQL Server Reporting Services   15.0.1528.0
Microsoft SQL Server Reporting Services Designers 
Version 15.0.1528.0

SsmsVsIntegration   1.0
Information about my package

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.10821.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6   16.3.0-beta.19455.1+0422ff293bb2cc722fe5021b85ef50378a9af823
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VS Diff   1.7.49
Another open source Visual Studio extension that makes file/code comparison more easily.

Comments (8)

  1. Anthony Missico Account Deactivated reporter

    Troubleshooting:

    [ERROR] Import-Module : The specified module 'Plaza' was not loaded because no valid

    Reveals:

    With 5.0.4 in Visual Studio, my environment value for ProgramFiles now points to C:\Program Files (x86).

    PS A:\Ws1\Personal\amissico\EpicDevOpsService.Wip> $Env:PSModulePath.Split(';')
    C:\Users\PHMIT.amissico\Documents\WindowsPowerShell\Modules
    C:\Program Files (x86)\WindowsPowerShell\Modules
    C:\Windows\system32\WindowsPowerShell\v1.0\Modules
    C:\Program Files\Microsoft Security Client\MpProvider
    C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
    C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\

    Get-ChildItem Env:

    ProgramFiles C:\Program Files (x86)
    ProgramFiles(x86) C:\Program Files (x86)

    A new DOS/CMD windows shows the correct value:

    C:\Users\PHMIT.amissico>set
    ...
    ProgramFiles=C:\Program Files
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files

  2. Adam Driscoll

    Is it possible this script is updating the PSModulePath? These are my steps and results:

    Interactive window:

    PS C:\Users\adamr\Source\Repos\ScriptProject> $ENV:PSMODULEPATH.SPLIT(";")
    C:\Users\adamr\Documents\WindowsPowerShell\Modules

    C:\Program Files\WindowsPowerShell\Modules
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
    C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\

    I execute a script that does this:

    \$ENV:PSMODULEPATH.SPLIT(";")

    PS C:\Users\adamr\Source\Repos\ScriptProject> C:\Users\adamr\Source\Repos\ScriptProject\ScriptProject.ps1

    I then execute this in the interactive window:

    PS C:\Users\adamr\Source\Repos\ScriptProject> $ENV:PSMODULEPATH.SPLIT(";")
    C:\Users\adamr\Documents\WindowsPowerShell\Modules

    C:\Program Files\WindowsPowerShell\Modules
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

    C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules
    PS C:\Users\adamr\Source\Repos\ScriptProject>

  3. Anthony Missico Account Deactivated reporter

    Ignore my first comment. That was related to having “PowerShell Version = “Windows PowerShell x86”. I added a comment earlier, but didn’t seem to get posted.

  4. Anthony Missico Account Deactivated reporter

    Is it possible this script is updating the PSModulePath?

    No. I also tried to duplicate the problem and it is gone. I also tried another way and unable to duplicate.

    I see no choice but to close.

  5. Log in to comment