StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell
SMB
VBScript

Clean Up Your Act

Sunday, September 22, 2013 in Powershell (Views: 1898)
So, something that seems painful in the transition from VBScript to PowerShell, but all the same...

When writing out a function I continually was calling, a variable for some reason would not go away. If the variable was 17, then changed to 20, and back to 17, it seemed the values themselves would not change. To eliminate this (and perhaps a nuclear approach, I removed the variable before redefining it.

Here is the cmdlet (assuming the variable name is $MyVariable):
Remove-Variable -Name $MyVariable

Of course, in VBScript it was as simple as MyVariable = Nothing.

By doing this, it eliminated the hassle of trying to do some very awkward manipulation. Just a quickie. If you are having problems with PowerShell variables clearing, try this method.

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.