- 1 year ago
Adding a value to existing system variable (powershell)
To add a value to an existing system variable in PowerShell, you can use the following steps:
Retrieve the current value of the system variable using the
Get-Item
cmdlet:powershell$existingValue = (Get-Item -Path 'Env:VariableName').Value
Replace
'VariableName'
with the name of the system variable you want to modify.Append the new value to the existing value:
powershell$newValue = $existingValue + ';NewValue'
Replace
'NewValue'
with the value you want to add to the system variable.Set the updated value for the system variable using the
Set-Item
cmdlet:powershellSet-Item -Path 'Env:VariableName' -Value $newValue
Replace
'VariableName'
with the name of the system variable you want to modify.Note: This change will only affect the current PowerShell session. If you want the updated value to persist across sessions, you may need to modify the system environment variable using the Windows Environment Variables settings.
Make sure to run the PowerShell session with administrative privileges to modify system variables.