Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to ensure PSToolbox path appears at the beginning of the PSModulePath environment variable #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ Function Script:Set-EnvironmentVariable {
if($Scope -eq 'Machine') {
$scopeArgs = '/M'
}
setx.exe $Name $Value $scopeArgs | Out-Null

[System.Environment]::SetEnvironmentVariable($Name,$Value,[System.EnvironmentVariableTarget]::Machine)
Set-Item -Path Env:$Name -Value $Value
}


$PSToolboxPath=Join-Path $PSScriptRoot Modules
if($env:PSModulePath -notlike "*$PSToolboxPath*") {
Script:Set-EnvironmentVariable -Name 'PSModulePath' -Value "$PSToolboxPath;$env:PSModulePath"
if($env:PSModulePath -notlike "$PSToolboxPath*") {
$UpdatedPSModulePath = "$PSToolboxPath;$(($env:PSModulePath -split ';' | Where-Object{ $_ -ne 'C:\Git\PSToolbox\Modules' }) -join ';')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work on my machine? C:\Git\PSToolbox\Modules isn't the path to my source tree. Should it be $pwd\Modules?

Script:Set-EnvironmentVariable -Name 'PSModulePath' -Value $UpdatedPSModulePath
if($PSToolboxPath -notin ($env:PSModulePath -split ';')) {
Write-Host -foreground Cyan $PSToolboxPath
#NOTE: This does not test the change from [System.Environment]::SetEnvironmentVariable is permanent.
throw "PSModulePath ('$env:PSModulePath') is not set with $PSToolboxPath"
throw "PSModulePath ('$env:PSModulePath') is not set with $PSToolboxPath"
}
}

Expand Down