Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Add-WindowsPSModulePath adds empty entries in certain cases. #62

Description

@gwojan

Add-WindowsPSModulePath adds empty entries if any of the environment variables contain empty strings like path;;path or [System.Environment]::GetEnvironmentVariable('PSModulePath', [System.EnvironmentVariableTarget]::User) is null or empty.

After running Add-WindowsPSModulePath:

4143> $Env:PSModulePath -split [System.IO.Path]::PathSeparator
C:\Users\bubba\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Users\bubba\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules

C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\
PS ~
4144>

This can be mitigated by changing

if ($pathTable[$path])
{
    continue
}

to

if ([string]::IsNullOrEmpty($path) -or $pathTable[$path])
{
    continue
}

Activity

  1. BrucePay commented on Nov 26, 2018

    @BrucePay

    The design was to merge the paths exactly as they are but eliminating duplicates. If there are empty elements in any of the components, they get copied into resulting path. But adding spaces because one of the components is $null is unacceptable so we should fix this. The simplest solution is

    if ($path -or $pathTable[$path])
    {
        continue
    }

    Since null and the empty string are both false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions