Skip to content

Commit

Permalink
Security fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajivharris committed Jul 3, 2020
1 parent 75bc0c8 commit 1be3a96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Binary file modified Set-PsEnv.psd1
Binary file not shown.
21 changes: 12 additions & 9 deletions Set-PsEnv.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,27 @@ function Set-PsEnv {
#get the operator
if($line -like "*:=*"){
Write-Verbose "Prefix"
$kvp = $line -split ":=",2
$cmd = '$Env:{0} = "{1};$Env:{0}"' -f $kvp[0].Trim(),$kvp[1].Trim()
$kvp = $line -split ":=",2
$key = $kvp[0].Trim()
$value = "{0};{1}" -f $kvp[1].Trim(),[System.Environment]::GetEnvironmentVariable($key)
}
elseif ($line -like "*=:*"){
Write-Verbose "Suffix"
$kvp = $line -split "=:",2
$cmd = '$Env:{0} += ";{1}"' -f $kvp[0].Trim(),$kvp[1].Trim()
$kvp = $line -split "=:",2
$key = $kvp[0].Trim()
$value = "{1};{0}" -f $kvp[1].Trim(),[System.Environment]::GetEnvironmentVariable($key)
}
else {
Write-Verbose "Assign"
$kvp = $line -split "=",2
$cmd = '$Env:{0} = "{1}"' -f $kvp[0].Trim(),$kvp[1].Trim()
$kvp = $line -split "=",2
$key = $kvp[0].Trim()
$value = $kvp[1].Trim()
}

Write-Verbose $cmd
Write-Verbose "$key=$value"

if ($PSCmdlet.ShouldProcess("$($cmd)", "Execute")) {
Invoke-Expression $cmd
if ($PSCmdlet.ShouldProcess("environment variable $key", "set value $value")) {
[Environment]::SetEnvironmentVariable($key, $value, "Process") | Out-Null
}
}
}
Expand Down

0 comments on commit 1be3a96

Please sign in to comment.