Part of my cleanup from the vCloud Suite 5.1 upgrade is migrating everything off of the *Any storage profile. A piece of this is setting the DefaultStorageProfile property for templates, which by default is blank (meaning the *Any profile). I’ve written a function that I’m using to update these in mass:
function set-templateVmDefaultSP($templates,$sPName)
{
foreach ($template in $templates){
write-host "Changeing defaultStoragePofile for VMs in $template"
$vms = $template.extensiondata.children.vm
foreach ($vm in $vms){
$vm.defaultstorageprofile = "$sPName"
}
$template.extensiondata.updateserverdata()
}
}
This passes a list of templates and a storage profile name, iterates through the template’s VMs, changes/sets the DefaultStorageProfile and sends an XML update back to vCloud with the changes.
This was working all well and good until I ran into this error:
PowerCLI C:\scripts\vcloud> $template.extensiondata.updateserverdata()
Exception calling “UpdateServerData” with “0” argument(s): “The provided XML has too many elements: 3340. The maximum is 2,048.”
At line:1 char:41
+ $template.extensiondata.updateserverdata <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

