Unexplainable delay with Hosts property on objects returned by Get-SCVMHostGroup

Executing the following cmdlet returns an empty collection (maybe $null) for the Hosts property initially.

Get-SCVMHostGroup -VMMServer "my_vmm_server" -Name "Production"

AllChildGroups            : {}
AllChildHosts             : {}
AllowUnencryptedTransfers : False
ChildGroups               : {}
CreationDate              : 9/5/2014 5:56:08 PM
Creator                   : DOMAIN\user
Description               :
Hosts                     : {}
ID                        : ea291d5d-b68f-416c-9c8e-d4c149112f8b
InheritNetworkSettings    : True
IsFullyCached             : True
IsRoot                    : False
MarkedForDeletion         : False
ModificationDate          : 9/5/2014 5:56:33 PM
ModifiedBy                : DOMAIN\user
Name                      : Production
ParentHostGroup           : All Hosts
Path                      : All Hosts\Production
ServerConnection          : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection

But after some unknown time, without touching anything, if I rerun the same command, the property is suddenly populated. The elapsed time between the initial run and when it is populated can be anywhere from 3 to 7 minutes.

AllChildGroups            : {}
AllChildHosts             : {}
AllowUnencryptedTransfers : False
ChildGroups               : {}
CreationDate              : 9/5/2014 5:56:08 PM
Creator                   : DOMAIN\user
Description               :
Hosts                     : {HV-01, HV-02}
ID                        : ea291d5d-b68f-416c-9c8e-d4c149112f8b
InheritNetworkSettings    : True
IsFullyCached             : True
IsRoot                    : False
MarkedForDeletion         : False
ModificationDate          : 9/5/2014 5:56:33 PM
ModifiedBy                : DOMAIN\user
Name                      : Production
ParentHostGroup           : All Hosts
Path                      : All Hosts\Production
ServerConnection          : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection

Can somebody please explain this? Is there a way to get the property populated immediately? Is there a different command I can run to get the collection of hosts?

In my particular case, I ultimately need to find the host (under a particular host group) with the lowest number of virtual machines so I can use that for provisioning a new vm.

SCVMM 2012 R2 running on Windows 2012 R2
February 17th, 2015 10:58pm

Hi Jay

Yes, this behavior is very counterintuitive. Honestly, the Hosts property should be removed from the SCVMHostGroup object. Getting a host group does not fetch all the hosts from the engine. For this reason, the hosts property only gets populated with hosts gradually, as they come into the client cache. I would like to see this behavior changed too.

You can fetch hosts by hostgroup in this way:

$hg = Get-SCVMHostGroup "My Host Group"
Get-SCVMHost -VMHostGroup $hg

Alternatively, you can find out the best host directly with a script like this, assuming that $vmt contained the VMTemplate you wanted to deploy:

$hg = Get-SCVMHostGroup "My Host Group"
$rating = Get-SCVMHostRating -VMHostGroup $hg -VMTemplate $vmt -Name "My VM 1" -DiskSpaceGB 50 -ReturnFirst
$bestHost = $rating.VMHost

I might have some parameter name errors, I don't have a VMM instance handy. Calling Get-SCVMHostRating with the -ReturnFirst parameter makes SCVMM return a single rating object with the best rated host for your VM. It is quite a bit faster than using placement on an entire hostgroup too.

I hope this helps!

Cheers, Hilton

  • Marked as answer by Jay-Callas Wednesday, February 18, 2015 2:49 PM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 10:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics