Variable usage question;
-
martedì 26 giugno 2012 13:59
Hi I have a powershell script that uses some variables, and they get passed to different functions etc. When I run the script multiple times I notice some of the variables have values from previous run? Is there a way to clear all variables before I start the run each time?
Thanks
Tutte le risposte
-
martedì 26 giugno 2012 14:04
Hello,
Which tool are you using? E.g. in PowerShell you can do this with menu "Debug" => "Reset runspace".
Anyway, you should initialize your variable with a proper value, then you don't have this problem.
Olaf Helper
* cogito ergo sum * errare humanum est * quote erat demonstrandum *
Wenn ich denke, ist das ein Fehler und das beweise ich täglich
Blog Xing- Contrassegnato come risposta SQL_Jay martedì 26 giugno 2012 14:14
-
martedì 26 giugno 2012 14:10
Get-Variable | Clear-Variable -ea silentlycontinue
Grant Ward, a.k.a. Bigteddy
- Proposto come risposta King Julien martedì 26 giugno 2012 14:12
- Contrassegnato come risposta SQL_Jay martedì 26 giugno 2012 14:14
-
martedì 26 giugno 2012 14:10Thanks , I am using Powershell ISE, So Should I initialize variables with blank or a null value at the begining of function?
-
martedì 26 giugno 2012 17:34
So Should I initialize variables with blank or a null value at the begining of function?
I would say, it depends on the data type; objects with $null, numeric e.g. with 0, string with [String]::Empty and so on.
Olaf Helper
* cogito ergo sum * errare humanum est * quote erat demonstrandum *
Wenn ich denke, ist das ein Fehler und das beweise ich täglich
Blog Xing

