hi,
i read the post Modify HA virtual machine options for guests and want to set drs options in similiar way (because set-vm is buggy).
what i did is:
function Set-DRSAutomationLevel
{
param($cluster, $vm, $DRSAutomationLevel)
$cluster_view = Get-View -ViewType ClusterComputeResource -Filter @{"Name" = $cluster}
$vm_view = Get-View -ViewType VirtualMachine -Filter @{"Name" = $vm}
$operation = "add"
if($cluster_view.ConfigurationEx.DrsVmConfig -ne $null)
{
foreach($guest in $cluster_view.ConfigurationEx.DrsVmConfig)
{
if($guest.Key.Value -eq $vm_view.MoRef.Value)
{
$operation = "edit"
}
}
}
$spec = New-Object VMware.Vim.ClusterConfigSpec
$VMspec = New-Object VMware.Vim.ClusterDrsVmConfigSpec
$VMspec.operation = $operation
$VMspec.Info = New-Object VMware.Vim.ClusterDrsVmConfigInfo
if ($DRSAutomationLevel -like "disabled")
{
$VMspec.Info.Enabled = $false
}
#elseif ($DRSAutomationLevel -like "default")
#{
#TBD
#}
else
{
$VMspec.Info.Enabled = $true
$VMspec.Info.Behavior = $DRSAutomationLevel
}
$VMspec.Info.Key = $vm_view.MoRef
$spec.DrsVmConfigSpec = @($VMspec)
$task = Get-View ($cluster_view.ReconfigureCluster_Task($spec, $true))
while($task.Info.Status -eq "running" -or $task.Info.Status -eq "queued")
{
$task.UpdateView()
}
}
everything is working fine (thanks LucD), but i don't no how to set drs level to default (cluster setting).
my understanding is that i need to remove custom setting of VM (if exists already) , but i don't no how to do that.
any help appreciated,
thanks