Created
July 18, 2018 13:49
-
-
Save mkht/acaca8802c84812cec48bf1e226c9738 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 Remove-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 -contains $Path) { | |
$PathEnv = ($PathEnv -ne $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