Created
July 18, 2018 13:48
-
-
Save mkht/c1ee9e16dc9d434ac5deed925ce84f67 to your computer and use it in GitHub Desktop.
環境変数PATHの末尾に指定の値を追加する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# ++++++++++++++++++++++++++++++++++++++++++++++ | |
環境変数PATHの末尾に指定の値を追加する | |
+++++++++++++++++++++++++++++++++++++++++++++++++ #> | |
function Add-EnvironmentPath { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[string] $Path, # 追加する値 | |
[Parameter(Mandatory = $true, Position = 1)] | |
[ValidateSet("User", "Machine")] | |
[string]$Target # UserかMachineか選ぶ | |
) | |
$PathEnv = New-Object System.Collections.ArrayList | |
([System.Environment]::GetEnvironmentVariable("Path", $Target)) -split ';' | ForEach-Object {$PathEnv.Add($_)} | Out-Null | |
if ($PathEnv -notcontains $Path) { | |
$PathEnv.Add($Path) | |
[System.Environment]::SetEnvironmentVariable("Path", ($PathEnv -join ';'), $Target) | |
} | |
[System.Environment]::GetEnvironmentVariable("Path", $Target) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment