VMware Cloud Community
imompero
Enthusiast
Enthusiast
Jump to solution

Is there a better faster way to get guest OS counts by datacenter?

This is what I am doing now...figured there has to be a faster way...any ideas?

$datacenters = get-datacenter | Sort-Object | select name

foreach($datacenter in $datacenters){

$datacentername = get-datacenter -name $datacenter.name | sort-object

$allvms = get-datacenter $datacentername | get-vm

Write-host "Os Full Name Counts: $datacentername"

Write-host ""

$allvms  | Get-View | Select @{Name="OS";Expression={ $_.Summary.Config.GuestFullName }} | Group OS | Sort Name | Select Name,@{Name="Total VMs";Expression={ $_.Count }}

}

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-View -ViewType Datacenter -Property Name -PipelineVariable dc |

ForEach-Object -Process {

    Get-View -ViewType VirtualMachine -SearchRoot $dc.MoRef -Property Summary.Config.GuestFullName |

    Group-Object {$_.Summary.Config.GuestFullName} |

    Sort-Object -Property Name |

    Select @{N='DC';E={$dc.Name}},Name,@{Name="Total VMs";Expression={ $_.Count }}

}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-View -ViewType Datacenter -Property Name -PipelineVariable dc |

ForEach-Object -Process {

    Get-View -ViewType VirtualMachine -SearchRoot $dc.MoRef -Property Summary.Config.GuestFullName |

    Group-Object {$_.Summary.Config.GuestFullName} |

    Sort-Object -Property Name |

    Select @{N='DC';E={$dc.Name}},Name,@{Name="Total VMs";Expression={ $_.Count }}

}


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

imompero
Enthusiast
Enthusiast
Jump to solution

Luc, thank you as always, so much quicker and more detailed!

Reply
0 Kudos