Source/Environment/Get-EnvironmentVariable.ps1
|
<# .SYNOPSIS Gets the value of an environment variable. .DESCRIPTION Wraps [Environment]::GetEnvironmentVariable to read an environment variable from a specific scope. .PARAMETER Name The name of the environment variable. .PARAMETER Scope The scope to read the variable from: Process, User, or Machine. Defaults to Process. .EXAMPLE Get-EnvironmentVariable -Name "Foo" -Scope "User" .EXAMPLE "Foo", "Bar" | Get-EnvironmentVariable -Scope "User" .INPUTS [System.String] The variable name. Accepts pipeline input by value or by property name. .OUTPUTS [System.String] The variable's value, or $null if it doesn't exist in the given scope. #> function Get-EnvironmentVariable { [OutputType([string])] [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [string] $Name, [System.EnvironmentVariableTarget] $Scope = [System.EnvironmentVariableTarget]::"Process" ) process { return [Environment]::GetEnvironmentVariable($Name, $Scope) } } |