Remembers that casting variables is sticky

So I got a question about a variable that was acting up in a colleague’s script, so we took a look together and solved it. I really like what he managed to do once we figured it out. Lars made a script that configured some parts of IIS site from a CSV file (blog post in swedish, script in english). At one time we had a variable called $test and that was casted to string. Then later we were trying to use the same variable for a hashtable and it didn’t work.

What happens if you cast a variable and then try to enter some other type into it.

So remember to remove the variable using Remove-Variable when you are done.

Or you could just recast it everytime..

Leave a Reply