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

[Feature request] Add a public variable containing 'Modules' and 'Scripts' paths #120

Closed
@LaurentDardenne

Description

@LaurentDardenne

We have $Profile to know the path names of the profiles, but there is no variable to know the PowershellGet installation paths.

function Get-PowershellGetPath {
 #extracted from PowerShellGet/PSModule.psm1 

  $IsInbox = $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase)
  if($IsInbox)
  {
      $ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell"
  }
  else
  {
      $ProgramFilesPSPath = $PSHome
  }
  
  if($IsInbox)
  {
      try
      {
          $MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments")
      }
      catch
      {
          $MyDocumentsFolderPath = $null
      }
  
      $MyDocumentsPSPath = if($MyDocumentsFolderPath)
                                  {
                                      Microsoft.PowerShell.Management\Join-Path -Path $MyDocumentsFolderPath -ChildPath "WindowsPowerShell"
                                  } 
                                  else
                                  {
                                      Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell"
                                  }
  }
  elseif($IsWindows)
  {
      $MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath 'Documents\PowerShell'
  }
  else
  {
      $MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath ".local/share/powershell"
  }
  
  $Result=@{}

  $Result.AllUsersModules = Microsoft.PowerShell.Management\Join-Path -Path $ProgramFilesPSPath -ChildPath "Modules"
  $Result.AllUsersScripts = Microsoft.PowerShell.Management\Join-Path -Path $ProgramFilesPSPath -ChildPath "Scripts"
   
  $Result.CurrentUserModules = Microsoft.PowerShell.Management\Join-Path -Path $MyDocumentsPSPath -ChildPath "Modules"
  $Result.CurrentUserScripts = Microsoft.PowerShell.Management\Join-Path -Path $MyDocumentsPSPath -ChildPath "Scripts"
  return $Result         
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions