Get-EnvPath.ps1
19 Sep 2025Description
Purpose
Gets the environment path for the specified container.
Detailed Description
This function retrieves the environment path for the specified container (Machine, User, or Process).
Usage
Example 1
PS C:\> Get-EnvPath -Container User
Returns the environment path for the current user.
Notes
No additional notes.
Script
function Get-EnvPath {
<#
.SYNOPSIS
Gets the environment path for the specified container.
.DESCRIPTION
This function retrieves the environment path for the specified container (Machine, User, or Process).
.PARAMETER Container
Specifies the container for which to retrieve the environment path. Valid values are Machine, User, and Process.
.EXAMPLE
PS C:\> Get-EnvPath -Container User
Returns the environment path for the current user.
#>
[CmdletBinding(DefaultParameterSetName = 'Default')]
param(
[Parameter(Mandatory = $true)]
[ValidateSet('Machine', 'User', 'Process')]
[string] $Container
)
$containerMapping = @{
Machine = [EnvironmentVariableTarget]::Machine
User = [EnvironmentVariableTarget]::User
Process = [EnvironmentVariableTarget]::Process
}
$containerType = $containerMapping[$Container]
[Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' |
Where-Object { $_ }
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.