Hi ... i wrote this script to get a list of VirtualMachine and it's Resourcepool but it results too much slow ....
$reportVM = @()
$count = 0
Get-VM | %{
$vm = $_ | Get-View
foreach($Name in $vm.Config){
$row = "" | select-Object ID_Estrazione, ID_VirtualCenter, ID_ResourcePool, ID_Macchina, NomeResourcePool
$NomeVM = $_.Name
$stato = $vm.runtime.powerState
$RSsupp = Get-ResourcePool -vm $_.Name
$row.ID_Estrazione = $dt
$row.ID_VirtualCenter = $VCREF
$row.ID_ResourcePool = $RSsupp.Id
$row.NomeResourcePool = $RSsupp.Name
$row.ID_Macchina = $vm.Summary.Config.uuid
$dataset.Tables[$Table].rows.Add($row.ID_Estrazione, $row.ID_VirtualCenter, $row.ID_ResourcePool, $row.ID_Macchina, $row.NomeResourcePool)
}
} $reportVM
If you are using Powershell v1 use the foreach(){} statement instead of foreach-object
Here for more info
Hi,
I have some suggestions that I think will increase the performance:
use Get-VM | Get-View | %{ } instead of the 2 foreach loops
Use Get-View instead of Get-ResourcePool by VM because the VM object has resourcePool property
Get resource pool name from summary.Name field of the ReourcePool view.
Getting ID from view object it's a bit "tricky" - currently the ID field can be constructed from the MoRef field using the format "Type-Value"
$reportVM = @()
$count = 0
Get-VM | Get-View | %{
$row = "" | select-Object ID_Estrazione, ID_VirtualCenter, ID_ResourcePool, ID_Macchina, NomeResourcePool
$NomeVM = $_.config.Name
$stato = $_.runtime.powerState
$RSsupp = Get-View $_.resourcePool
$row.ID_Estrazione = $dt
$row.ID_VirtualCenter = $VCREF
$row.ID_ResourcePool = "{0}-" -f $RSsupp.MoRef.Type, $RSsupp.MoRef.Value
$row.NomeResourcePool = $RSsupp.summary.Name
$row.ID_Macchina = $_.Summary.Config.uuid
$dataset.Tables[$Table].rows.Add($row.ID_Estrazione, $row.ID_VirtualCenter, $row.ID_ResourcePool, $row.ID_Macchina, $row.NomeResourcePool)
}
$reportVMRegards,
Yasen