Public/Get-SpecEnvironmentVariable.ps1
Function Get-SpecEnvironmentVariable { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [AllowNull()] [AllowEmptyString()] [string]$VariableName, [validateset ("User", "Machine", "Process") ] [string]$scope ) $result = [System.Environment]::GetEnvironmentVariable($variableName, [System.EnvironmentVariableTarget]::$scope) if ($NULL -eq $result) { Write-Verbose "The variable [$VariableName] does not exist." return $false } else { # return the variable value Write-Verbose "The variable [$VariableName] exists and has a value of $result" return $result } } |