VMware Cloud Community
NeedToKnowBasis
Enthusiast
Enthusiast

Conditional Variable Based on Calculation

I am wondering if it possible to have a variable contain a different value based on a IF-ELSE statement:

   IF  (($tp.extensiondata.storage.perdatastoreusage.committed / 1073741824) -gt [int]$row.C_System)

 

   $TotalDisk = (($tp.extensiondata.storage.perdatastoreusage.committed / 1073741824) + [int]$row.D_Drive + [int]$row.EDrive)

 

   ELSE

   $TotalDisk = ($row.C_System + $row.D_Drive + $row.EDrive)

The IF statement results in a proper calculation but when that condition is not met and it proceeds to the ELSE statement, I get "40.0003093760461" as a sum of those numbers. I have tried using the above example as well as:

   ELSE

      $TotalDisk = ($row.C_System + $row.D_Drive + $row.EDrive)

Both resulted in the same number (40.0003093760461) - is there something else I need to add to the calculation to make it go through successfully?

0 Kudos
1 Reply
LucD
Leadership
Leadership

Not sure if that is a copy/paste issue, but you should be using code block (curly braces) after if and else.

Like this

if(($tp.extensiondata.storage.perdatastoreusage.committed / 1073741824) -gt [int]$row.C_System){

   $TotalDisk = (($tp.extensiondata.storage.perdatastoreusage.committed / 1073741824) + [int]$row.D_Drive + [int]$row.EDrive)

}

else{

   $TotalDisk = ($row.C_System + $row.D_Homevg + $row.App_eHealth)

}


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

0 Kudos