ps/Modules/Alkami.PowerShell.Configuration/Public/Set-EnvironmentVariable.ps1
2023-05-30 22:51:22 -07:00

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)
}