Converting the Windows Script Host Remove Method

Windows PowerShell

Definition: Removes an existing environment variable.


One of the sad facts of life is that, at some point in time, you and your environment variables might grow apart; in fact, you might get to the point where you can no longer bear to have certain environment variables around. How can you get rid of an unwanted environment variable? Well, how about by using the Remove-Item cmdlet

Remove-Item Env:\Test

As you can see, we simply call Remove-Item followed by the path to the environment variable we want to remove. In this case, that’s an environment variable named Test. Because environment variables have their own PowerShell drive, the complete path to an environment variable is simply the drive “letter” Env:\ followed by the variable name.

See conversions of other Windows Script Host methods and properties.
Return to the VBScript to Windows PowerShell home page