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

26 lines
939 B
PowerShell

function Set-ORBEnvironmentalVariables {
<#
.SYNOPSIS
Sets an environment variable from interactive input
#>
[CmdletBinding()]
Param(
[PSObject]$EnvVariable
)
$logLead = Get-LogLeadName
$newValue = Read-Host ("Enter a value for {0}" -f $EnvVariable.Name)
if (!([String]::IsNullOrEmpty($EnvVariable.ValidationRegex))) {
Write-Verbose ("$logLead : Validating Input {0} with Regex {1}" -f $newValue, $EnvVariable.ValidationRegex)
if ([String]::IsNullOrEmpty($newValue) -or $newValue -notmatch $envVariable.ValidationRegex) {
Write-Warning ($EnvVariable.ValidationError)
Set-ORBEnvironmentalVariables $EnvVariable
} else {
Write-Host ("$logLead : Setting machine environmental variable {0} to {1}" -f $EnvVariable.Name, $newValue)
[Environment]::SetEnvironmentVariable($EnvVariable.Name, $newValue, "Machine")
}
}
}