<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Show data in Percent in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978719#M112758</link>
    <description>&lt;P&gt;&lt;a href="https://communities.vmware.com/t5/user/viewprofilepage/user-id/256147"&gt;@LucD&lt;/a&gt;&amp;nbsp;correct the idea behin '%' is that to show&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;a percent sign in the column header &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@DCF4E2F7991292CEECF250394DB2C2BC/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Jul 2023 13:19:51 GMT</pubDate>
    <dc:creator>lElOUCHE_79</dc:creator>
    <dc:date>2023-07-23T13:19:51Z</dc:date>
    <item>
      <title>Show data in Percent</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978712#M112756</link>
      <description>&lt;P&gt;I'm trying to improve my PowerCLI skills, so I'm beginning to do a few basic scripts.&lt;BR /&gt;The script below lets you retrieve CPU and memory metrics over one week.&lt;BR /&gt;My concern is that the numbers returned have multiple numbers after the comma.&lt;BR /&gt;Who can assist me in rounding these numbers?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;$AllHosts = @()
Get-VM * | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.Name -notmatch "vCLS"} | ForEach-Object {
    $hoststat = "" | Select-Object VMHost, HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $hoststat.VMHost =$_.VMHost.Name.Split('.')[0]
    $hoststat.HostName = $_.Name
    $statcpu = Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat cpu.usage.average
    $statmem = Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat mem.usage.average
    $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
    $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
    $hoststat.CPUMax = $cpu.Maximum
    $hoststat.CPUMin = $cpu.Minimum
    $hoststat.CPUAvg = $cpu.Average
    $hoststat.MemMax = $mem.Maximum
    $hoststat.MemMin = $mem.Minimum
    $hoststat.MemAvg = $mem.Average
    $AllHosts += $hoststat
}
$AllHosts | Select-Object VMHost, HostName, MemMax_"%", MemMin_"%", MemAvg_"%", CPUMax_"%", CPUMin_"%", CPUAvg_"%" | Export-Csv .\CPURAMHost.csv -NoTypeInformation&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 23 Jul 2023 11:31:51 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978712#M112756</guid>
      <dc:creator>lElOUCHE_79</dc:creator>
      <dc:date>2023-07-23T11:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Show data in Percent</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978718#M112757</link>
      <description>&lt;P&gt;Use the [Math]::Round() method.&lt;BR /&gt;&lt;BR /&gt;Not sure what the idea with the "%' is on the Select, but if you want to have a percent sign in the column header use a calculated property and change the N(ame) entry in the has table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$AllHosts = @()
Get-VM * | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.Name -notmatch "vCLS"} | ForEach-Object {
    $hoststat = "" | Select-Object VMHost, HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $hoststat.VMHost =$_.VMHost.Name.Split('.')[0]
    $hoststat.HostName = $_.Name
    $statcpu = Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat cpu.usage.average
    $statmem = Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Finish (Get-Date)-MaxSamples 100 -Stat mem.usage.average
    $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
    $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
    $hoststat.CPUMax = [math]::Round($cpu.Maximum,0)
    $hoststat.CPUMin = [math]::Round($cpu.Minimum,0)
    $hoststat.CPUAvg = [math]::Round($cpu.Average,0)
    $hoststat.MemMax = [math]::Round($mem.Maximum,0)
    $hoststat.MemMin = [math]::Round($mem.Minimum,0)
    $hoststat.MemAvg = [math]::Round($mem.Average,0)
    $AllHosts += $hoststat
}
$AllHosts | Select-Object VMHost, HostName, 
   @{N='MemMax%';E={$_.MemMax}}, 
   @{N='MemMin%';E={$_.MemMin}}, 
   @{N='MemAvg%';E={$_.MemAvg}}, 
   @{N='CPUMax%';E={$_.CPUMax}}, 
   @{N='CPUMin%';E={$_.CPUMin}}, 
   @{N='CPUAvg%';E={$_.CPUAvg}} |
Export-Csv .\CPURAMHost.csv -NoTypeInformation&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2023 13:09:20 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978718#M112757</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-07-23T13:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Show data in Percent</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978719#M112758</link>
      <description>&lt;P&gt;&lt;a href="https://communities.vmware.com/t5/user/viewprofilepage/user-id/256147"&gt;@LucD&lt;/a&gt;&amp;nbsp;correct the idea behin '%' is that to show&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;a percent sign in the column header &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@DCF4E2F7991292CEECF250394DB2C2BC/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2023 13:19:51 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Show-data-in-Percent/m-p/2978719#M112758</guid>
      <dc:creator>lElOUCHE_79</dc:creator>
      <dc:date>2023-07-23T13:19:51Z</dc:date>
    </item>
  </channel>
</rss>

