Hi,
I was wondering how you perform a test to see if a variable created from a previous command has got anything in it. My script keeps failing because it is comparing it to 0 with a if greater than.
For example I have:
$var = get-vm
if i want to test whether there is anything in it how do I make the following test:
If($var -gt 0)
{
$var
}
else
{
"nothing in variable"
}
It seems sometimes it works others it throws one of those red errors.
Thanks in advance for any help,
Dan
I normaly use:
If ($var) { $var } else { "nothing in variable" }
If you want to do the oposite it would be:
If (-not $var) { $var } else { "nothing in variable" }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
I normaly use:
If ($var) { $var } else { "nothing in variable" }
If you want to do the oposite it would be:
If (-not $var) { $var } else { "nothing in variable" }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
alanrenouf, exactly what I was after, thanks so much for the quick response.
Dan