Reputation: 1001
I don't have a direct access to the Environment Variables on Windows. Therefore I'm trying to remove an item through powershell
Remove-Item -Path Env:Path -Value ($Env:Path + ";C:\Item\To\Be\Removed")
However getting the error below
Upvotes: 4
Views: 7522
Reputation: 5252
From Powershells perspective the environemnt variable Path is just a long string. So you will have to parse it and use string operations to remove the part you want to get rid of ... maybe like this:
$Remove = 'C:\Item\To\Be\Removed'
$env:Path = ($env:Path.Split(';') | Where-Object -FilterScript {$_ -ne $Remove}) -join ';'
Additional information about environment variables you can get with Get-Help about_Environment_Variables.
Upvotes: 6