Thursday, December 30, 2010

Reinitializing your Powershell environment without closing and reopening

I’ve been running our builds with psake, and have found that I get errors if I try to run a build script twice in the same Powershell session.  I looked around a bit about how to reset your Powershell environment without closing and reopening a Powershell console window, but couldn’t find anything. 

Here’s what I came up with that works for me.

Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host

And now, the short version:

rv * -ea SilentlyContinue; rmo *; $error.Clear(); cls

2 comments:

Anonymous said...

Quick and concise solution.

However, that doesn't work in all cases. For example, constant variables are not removed when using this solution.
New-Variable ConstantVar -Option constant -value "This is a contant"
In that case, Remove-Variable * fails.

Anonymous said...

Link 12bet Sign Up - Vie Casino
Link 인카지노 12bet Sign Up. Play at 188bet a trusted online casino. Get your Sign Up Welcome bonus now. Get the latest and greatest games from Link. 12bet