Memory Round Off

This post was originally published on this site

Hi,

 

I am getting the memory output as 112.09, I am unable to get the Memory output rounded off for below line in the script

 

Please help

 

  @{N=Memory(GB);E={$_.Group  | Measure-Object Property MemoryGB Sum | Select ExpandProperty Sum}},

 

Script

 

$report = @()

 

$allocated = “” | Select Cluster,Folder Name,CPU,Memory(GB),Capacity(GB),Used(GB),FreeSpace(GB),FreeSpace(%),Total VM’s,PoweredOn VM’s,PoweredOff VM’s

$allocated.Folder Name = Allocated

$allocated.CPU = 1000

$allocated.Memory(GB) = 800

$allocated.Capacity(GB) = 3076

$report += $allocated

 

$report += Get-Folder RND | Get-VM | Group-Object Property {$_.Folder.Id} | Select @{N=Cluster;E={Get-Cluster VM $_.Group}},

  @{N=Folder Name;E={$folder = $_.Group[0].Folder; $path = $folder.Name; $path}},

  @{N=CPU;E={$_.Group | Measure-Object Property NumCpu Sum | Select ExpandProperty Sum}},

  @{N=Memory(GB);E={$_.Group  | Measure-Object Property MemoryGB Sum | Select ExpandProperty Sum}},

  @{N = Capacity(GB); E = {

   $script:vdiskFree = ($_.Group.Guest.Disks | Measure-Object Property FreeSpaceGB Sum).Sum

   $script:vdiskCapacity = ($_.Group.Guest.Disks | Measure-Object Property CapacityGB Sum).Sum

   {0:f1} -f $script:vdiskCapacity

   }

   },

  @{N = Used(GB); E = {{0:f1} -f ($script:vdiskCapacity $script:vdiskFree)}},

  @{N = FreeSpace(GB); E = {[math]::Round($script:vdiskCapacity ($script:vdiskCapacity $script:vdiskFree))}},

  @{N = FreeSpace(%); E = {[math]::Round($script:vdiskFree / $script:vdiskCapacity * 100)}},

  @{N=Total VM’s;E={$_.Group.Count}},

  @{N=PoweredOn VM’s;E={($_.Group | Where-Object {$_.PowerState -eq PoweredOn}).Count}},

  @{N=PoweredOff VM’s;E={($_.Group | Where-Object {$_.PowerState -eq PoweredOff}).Count}}

 

  $available = “” | Select Folder Name,Cluster,CPU,Memory(GB),Capacity(GB),Used(GB),FreeSpace(GB),FreeSpace(%),Total VM’s,PoweredOn VM’s,PoweredOff VM’s

  $available.Folder Name = Available

  $available.CPU = $report[0].CPU ($report[1..($report.Count -1)].CPU | Measure-Object Sum).Sum

  $available.Memory(GB) = $report[0].Memory(GB) ($report[1..($report.Count -1)].Memory(GB) | Measure-Object Sum).Sum

  $available.Capacity(GB) = $report[0].Capacity(GB) ($report[1..($report.Count -1)].Capacity(GB) | Measure-Object Sum).Sum

 

  $report += $available

 

  $report

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.