imompero
Enthusiast
Enthusiast

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

Jump to solution

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

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

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

imompero
Enthusiast
Enthusiast

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

0 Kudos