webmichael01
Contributor
Contributor

powerstate list by datacenter

Get-Datacenter | Select @{N = 'datcentername'; E = {$_.Name -replace '-','' }}, @{N = 'Cluster_Name'; E = {$datacenter.name}}, @{N = 'VM Count'; E = {( get-vm | where-object { $_.powerstate -eq "poweredOff"}).Count}}

 

how come this is adding the counts instead of breaking them out per count by Datacenter ?

Human error Im sure :slightly_smiling_face:

datacenter1 312
datacenter2 312
datacenter3  312

I need it this formate for nodeExporter

Reply
0 Kudos
LucD
Leadership
Leadership

Because you do a Get-VM without a Location parameter, that will return all the VMs.
Use 

@{N = 'VM Count'; E = {( Get-VM -Location $_ | where-object { $_.powerstate -eq "poweredOff"}).Count}}


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

View solution in original post

webmichael01
Contributor
Contributor

thank you sir I tried the location but I see was doing it wrong and leaving off $_

Tags (1)
Reply
0 Kudos
webmichael01
Contributor
Contributor

ignore sorry cant delete

Reply
0 Kudos