Remove environmental variable

Lets round off looking at environmental variables by looking at how to remove them

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function remove-environment {
param (
 [string][ValidateNotNullOrEmpty()]$name,
 [switch]$perm,
 [switch]$machine
)
$value = “”
if (-not $perm) {Remove-Item -Path env:\$($name) -Force}
else {
 if ($machine){$type = “Machine”}
 else {$type = “User”}
 [System.Environment]::SetEnvironmentVariable($name, $value, $type)
}
}

If you want to remove it permanently use the –perm switch otherwise it is just removed from the session

About these ads
This entry was posted in PowerShell V2. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s