Skip to content

Instantly share code, notes, and snippets.

@aldente39
Created April 7, 2012 14:30
Show Gist options
  • Save aldente39/2329371 to your computer and use it in GitHub Desktop.
Save aldente39/2329371 to your computer and use it in GitHub Desktop.
remove path
function RemovePath{
$p = pwd
$name = "Path"
sl HKCU:
$s = Get-ItemProperty "HKCU:Environment" $name
sl $p
$s = $s.$name
if($s[-1] -eq ";"){
$s = $s.Remove($s.length - 1, 1)
}
$list = $s.split(";")
$l = $list.length
Write-Host ------------------------------------------------------------
for($i= 0; $i -lt $l; $i++){
Write-Host $i`t($list[$i])
}
Write-Host ------------------------------------------------------------
$input = Read-Host "input number"
$tmp = 0
if([int]::TryParse($input, [ref]$tmp) -and
(0 -le $input) -and ($input -lt $l)){
$v = ""
for($j = 0; $j -lt $l; $j++){
if($j -ne $input){
$v += $list[$j] + ";"
}
}
$v = $v.Remove($v.length - 1, 1)
setx $name $v
}
else{
Write-Host Canceled.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment