VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Validate zero and negative numbers

Hi,

I would like to validate the CPU output, the below works, if the output value is equals to zero,

Please help, how can I validate and exit if output of variables is zero and negative.

$TotalCPU = 100

$UsedCPU = 150

$cpu = $TotalCPU - $UsedCPU

if (($cpu) -eq 0) {

    "Validation Failed"

    return

}

else {

    "Validation Success"

}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You mean like this?
Change -eq into -le

$TotalCPU = 100

$UsedCPU = 150


$cpu = $TotalCPU - $UsedCPU

if (($cpu) -le 0) {

    "Validation Failed"

    return

}

else {

    "Validation Success"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You mean like this?
Change -eq into -le

$TotalCPU = 100

$UsedCPU = 150


$cpu = $TotalCPU - $UsedCPU

if (($cpu) -le 0) {

    "Validation Failed"

    return

}

else {

    "Validation Success"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you much, that worked perfect

0 Kudos