37 lines
1.0 KiB
PowerShell
37 lines
1.0 KiB
PowerShell
function Set-EnvironmentVariable {
|
|
<#
|
|
.SYNOPSIS
|
|
Set or creates an environment variable. Must supply the store name, defaults to machine level.
|
|
|
|
.PARAMETER Name
|
|
Sets or creates the environment variable with the specified name.
|
|
|
|
.PARAMETER Value
|
|
Sets the environment variable with the specified value.
|
|
|
|
.PARAMETER StoreName
|
|
The appropriate store to put the variable in. Defaults to machine.
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[Alias("Key")]
|
|
[string]$Name,
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$Value,
|
|
[Parameter(Mandatory = $true)]
|
|
[Alias("Store")]
|
|
[Alias("Location")]
|
|
[ValidateSet("Process","User","Machine")]
|
|
[string]$StoreName
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName)
|
|
|
|
Write-Host "$logLead : Set environment variable [$Name] in $StoreName store"
|
|
|
|
[System.Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::$StoreName)
|
|
}
|