Skip to main content

Set-PathVariable

Description

Sets the provided path(s) to the Environmental Path variable for a specified scope.

Requirements

PowerShell V.5

Usage

  1. For each given path, reload the current environmental path variable for the desired scope.
  2. Search that scope for the given path. If it's present, return the current environmental path variable.
  3. Add the given path to the environmental path variable and return the updated environmental path variable.
.\Set-PathVariable.ps1 -Path 'C:\Documents and Settings','C:\Config.Msi', 'C:\Recovery','C:\Intel' -Scope Machine

This command will return the current $Env:Path state for the machine after adding those paths to the variable.

.\Set-PathVariable.ps1 -Path 'C:\something' -Scope User

This command will return the current $Env:Path state for the user after adding the specified path to the variable.

Parameters

ParameterAliasRequiredDefaultTypeDescription
PathTrueString[]A list of paths to add to the desired scope.
ScopeFalseMachineSystem.EnvironmentVariableTargetThis designates the scoped environmental variable you wish to target: machine or user.

Output

Standard Output