Hi,
Can you please help that to add and remove environment variable via PS deploy toolkit.
Thanks
Anil
Hi,
Can you please help that to add and remove environment variable via PS deploy toolkit.
Thanks
Anil
Hi,
In the root of the PSAppDeployToolkit zip file, there is a file named PSAppDeployToolkit.pdf, within here you can find what Environment Variables are defined in the PSAppDeployToolkit (see Page 54 in the v3.9.3 version)
You can also set these using native PowerShell commands - here are a couple of earlier discussions around the same subject:
I hope this helps
I used the command [Environment]::SetEnvironmentVariable(āPATHā, $env:Path + ā;$envProgramFilesX86\JDKā,[EnvironmentVariableTarget]::Machine) But required path is appended to registry.But the issue is one more entry also added which is not required.
C:\Users\ank\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\JDK
Thatās the problem with editing %PATH%.
itās very easy to make code to ADD to %PATH%
Itās hard to make code that will not make %PATH% grow with with dupes and dead paths.
I tried years ago and failed.
Iām sorry I canāt remember where I copypastaād this so I canāt give credit, but this is the function I useā¦
## Set PATH environment variable
Function Set-PathVariable {
param (
[string]$AddPath,
[string]$RemovePath
)
$regexPaths = @()
if ($PSBoundParameters.Keys -contains 'AddPath'){
$regexPaths += [regex]::Escape($AddPath)
}
if ($PSBoundParameters.Keys -contains 'RemovePath'){
$regexPaths += [regex]::Escape($RemovePath)
}
$arrPath = $env:Path -split ';'
Write-Log -Message "Previous PATH was: $($env:Path)"
foreach ($path in $regexPaths) {
$arrPath = $arrPath | Where-Object {$_ -notMatch "^$path\\?"}
}
$PathUpdate = ($arrPath + $addPath) -join ';'
Write-Log -Message "Updating PATH to: $($PathUpdate)"
[Environment]::SetEnvironmentVariable("PATH","$PathUpdate","Machine")
}
Set-PathVariable -AddPath 'C:\Add\This\Path'
Set-PathVariable -RemovePath 'C:\Delete\This\Path'