VMware Cloud Community
aravinds3107
Virtuoso
Virtuoso

List the resource pool for the VM's

I am running the following to get some value on the VM,s Need to get the resource pool to which the VM's belongs too. tried using Resourcepool using select but doesnt seems to working

Get-VM |

Select-Object Name,MemoryGB,NumCPU,ResourcePool

  @{Name="CPU Limit";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Limit}},

  @{Name="CPU Reservation";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation}},

  @{Name="Mem Limit";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Limit}},

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}} | Export-CSV C:\Scripts\VM.csv -NoTypeInformation -UseCulture

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Try adding

@{N="ResourcePool";E={Get-ResourcePool -VM $_ | Select -ExpandProperty Name}}


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

Reply
0 Kudos
vmk2014
Expert
Expert

Hi LucD,

      when i tried to execute the script the output shows incomplete.

Get-VM |

Select-Object Name,MemoryGB,NumCPU,ResourcePool

  @{Name="CPU Limit";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Limit}},

  @{Name="CPU Reservation";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation}},

  @{Name="Mem Limit";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Limit}},

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}}

@{N="ResourcePool";E={Get-ResourcePool -VM $_ | Select -ExpandProperty Name}} | Export-CSV C:\temp\VM.csv -NoTypeInformation -UseCulture

Output in csv :-

IsReadOnlyIsFixedSizeIsSynchronizedKeysValuesSyncRootCount
FALSEFALSEFALSESystem.Collections.Hashtable+KeyCollectionSystem.Collections.Hashtable+ValueCollectionSystem.Object2

thanks

vmk2014

Reply
0 Kudos
LucD
Leadership
Leadership

I think there is a comma missing at the end of the line before last

@{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}},

@{N="ResourcePool";E={Get-ResourcePool -VM $_ | Select -ExpandProperty Name}} | Export-CSV C:\temp\VM.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
vmk2014
Expert
Expert

Hi LucD,

     Please find the script which i am using

Get-VM |

Select-Object Name,MemoryGB,NumCPU,ResourcePool

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}},

  @{Name="CPU Reservation";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation}},

  @{Name="Mem Limit";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Limit}},

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}}

@{N="ResourcePool";E={Get-ResourcePool -VM $_ | Select -ExpandProperty Name}} | Export-CSV C:\temp\VM.csv -NoTypeInformation -UseCulture

while running the script its shows in powercli interface but in csv its shows diffrent output which i attached in earlier post also.

RP.JPG

Output in csv format is

IsReadOnlyIsFixedSizeIsSynchronizedKeysValuesSyncRootCount
FALSEFALSEFALSESystem.Collections.Hashtable+KeyCollectionSystem.Collections.Hashtable+ValueCollectionSystem.Object2

thanks

vmk2014

Reply
0 Kudos
LucD
Leadership
Leadership

Did you already try adding that comma at the end of the 2nd to last line ?


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

Reply
0 Kudos
vmk2014
Expert
Expert

Hi,

Please find the script which i am using.

Get-VM |

Select-Object Name,MemoryGB,NumCPU,ResourcePool

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}},

  @{Name="CPU Reservation";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation}},

  @{Name="Mem Limit";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Limit}},

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}},

@{N="ResourcePool";E={Get-ResourcePool -VM $_ | Select -ExpandProperty Name}} | Export-CSV C:\temp\VM.csv -NoTypeInformation -UseCulture

still same output

thanks

vmk2014.

Reply
0 Kudos
bexinul
Contributor
Contributor

Hello!

Did you find what the error was?

I am trying to do the same script...

Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

This works (ResourcePool is a property on the VirtualMachine object, provided your PowerCLI is recent).

Get-VM |

Select-Object Name,MemoryGB,NumCPU,ResourcePool,

  @{Name="Mem Reservation";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation}},

  @{Name="CPU Reservation";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation}},

  @{Name="Mem Limit";Expression={$_.ExtensionData.ResourceConfig.MemoryAllocation.Limit}},

  @{Name="CPU Limit";Expression={$_.ExtensionData.ResourceConfig.CpuAllocation.Limit}} |

Export-CSV C:\temp\VM.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
bexinul
Contributor
Contributor

Thanks a lot LucD, it worked!!

Reply
0 Kudos