VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Cannot apply Rounding to Custom Properties

When I try to apply a round function to the custom properties in this report, the value is blank.  When I take the rounding function off, it works.  Any ideas?

$report = Get-VM -Name acme* -server $vcenter |

select name,

ProvisionedSpaceGB,

@{N="vCenterServer";E={$_.Uid.Split(":")[0].Split("@")[1]}},

@{n="Cluster";E={

    $rp = Get-View $_.ExtensionData.ResourcePool

    $parent = Get-View $rp.Parent

    While ($parent -isnot [VMware.Vim.ClusterComputeResource]){

       $parent = Get-View $parent.Parent

        }

        $parent.Name

        }} | sort-object vCenterServer |

Group-Object -Property {$_.Cluster} | Select @{n="ClusterName";E={$_.Name}},

@{N="vCenterServer";E={$vcenter.Name}},

@{N="VMCount";E={(get-vm -location $_.Name).count}},

@{N="AcmeVMCount";E={$_.Group | Measure-Object | Select -ExpandProperty Count}},

@{N="VMsPerAcmeVM";E={math::[round](((get-vm -location $_.Name).count / ($_.Group | Measure-Object | Select -ExpandProperty Count)),1)}},

Reply
0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, TheVMinator-

That is probably due to having the syntax slightly off.  The square brackets (for the type accelator) go around the .NET class name ("Math" in this case), instead of around the name of the static method from the class ("Round" in this case).  So, that should be like:

...
@{N
="VMsPerAcmeVM";E={[Math]::round(((get-vm -location $_.Name).count / ($_.Group | Measure-Object | Select -ExpandProperty Count)),1)}}

That do better for you?

View solution in original post

Reply
0 Kudos
2 Replies
mattboren
Expert
Expert
Jump to solution

Hello, TheVMinator-

That is probably due to having the syntax slightly off.  The square brackets (for the type accelator) go around the .NET class name ("Math" in this case), instead of around the name of the static method from the class ("Round" in this case).  So, that should be like:

...
@{N
="VMsPerAcmeVM";E={[Math]::round(((get-vm -location $_.Name).count / ($_.Group | Measure-Object | Select -ExpandProperty Count)),1)}}

That do better for you?

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

Perfect - thanks again

Reply
0 Kudos