From 80a488484b9093064d2466e7fe32f970b25fba74 Mon Sep 17 00:00:00 2001 From: "lksz@work" Date: Tue, 24 Nov 2020 13:15:47 -0500 Subject: [PATCH] Set-EnvVariable + minor fix to SystemName --- profile.d/SystemName.class.ps1 | 1 + sys.Linux/Set-EnvVariable.ps1 | 6 ++++++ sys.Windows/Set-EnvVariable.ps1 | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 sys.Linux/Set-EnvVariable.ps1 create mode 100644 sys.Windows/Set-EnvVariable.ps1 diff --git a/profile.d/SystemName.class.ps1 b/profile.d/SystemName.class.ps1 index 022340f..8ce740f 100644 --- a/profile.d/SystemName.class.ps1 +++ b/profile.d/SystemName.class.ps1 @@ -18,6 +18,7 @@ class SystemName { #: System.Management.Automation.IValidateSetValuesGenerator { } $possibleValues.out = $possibleValues.out | Select-Object -Unique | + Where-Object { $_ } | Sort-Object { $local:sortName = "zz_$_"; if( $_ -in $possibleValues.Exist -and $_ -in $possibleValues.Current ) { $sortName[0] = "a" } diff --git a/sys.Linux/Set-EnvVariable.ps1 b/sys.Linux/Set-EnvVariable.ps1 new file mode 100644 index 0000000..a51daa7 --- /dev/null +++ b/sys.Linux/Set-EnvVariable.ps1 @@ -0,0 +1,6 @@ +[CmdletBinding()]param( + [string]$Name, + [object]$Value +) + +Set-Item -Path (Join-Path "env:" $Name) -Value $Value diff --git a/sys.Windows/Set-EnvVariable.ps1 b/sys.Windows/Set-EnvVariable.ps1 new file mode 100644 index 0000000..5de891d --- /dev/null +++ b/sys.Windows/Set-EnvVariable.ps1 @@ -0,0 +1,11 @@ +[CmdletBinding()]param( + [string]$Name, + [object]$Value, + [ValidateSet('User','Machine')] + [string]$Persist +) + +Set-Item -Path (Join-Path "env:" $Name) -Value $Value +if( $Persist ) { + [environment]::setEnvironmentVariable($Name, $Value, $Persist) +} \ No newline at end of file