set options for the VMS DRS

Hello

I read the post options modify HA virtual machine for customers and want to set options of drs in a similar way (because the game - vm is buggy).

what I have 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 - no $null)

{

foreach ($guest as $cluster_view.) ConfigurationEx.DrsVmConfig)

{

if($Guest.) Key.Value - eq $vm_view. MoRef.Value)

{

$operation = "├editer".

}

}

}

$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 "off")

{

$VMspec.Info.Enabled = $false

}

#elseif ($DRSAutomationLevel - as 'default')

#{

#TBD

#}

on the other

{

$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 "on hold")

{

$task. UpdateView()

}

}

everything works fine (thanks LucD), but I do not know how to set the default level (cluster configuration) drs.

my understanding is that I need to delete a custom virtual machine setting (if exists), but I don't know how to do this.

any help appreciated,

Thank you

Hello

To removed the custom setting of VM you need just to remove the entry for this virtual machine and ClusterDasVmConfigSpec.operation to 'delete' and passes the virtual computer as removeKey MoRef:

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){
                    if ($DRSAutomationLevel -like "default") {
                         # remove the custom DRS setting for that VM
                         $operation = "remove"
                    } else {
                         $operation = "edit"
                    }
               }
          }
     }

     if (($DRSAutomationLevel -like "default") -and ($operation -like "add")) {
          # if there is no VM specific DRS setting - do nothing
     }else {
          $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
               $VMspec.Info.Key = $vm_view.MoRef
          }elseif ($DRSAutomationLevel -like "default"){
               $VMspec.removeKey = $vm_view.MoRef
          }else {
               $VMspec.Info.Enabled = $true
               $VMspec.Info.Behavior = $DRSAutomationLevel
          }

          $VMspec.Info.Key = $vm_view.MoRef
          $spec.DrsVmConfigSpec = @($VMspec)
          $cluster_view.ReconfigureCluster($spec, $true)
     }
}

In addition the object 'view' have 'blocking' of working methods that will wait for the completion of the task for you (IE ReconfigureCluster instead of ReconfigureCluster_Task)

Kind regards

Yasen

Tags: VMware

Similar Questions

Maybe you are looking for

  • Satellite A660-17F - sensor above the keyboard lights stopped working

    Hello I just got the phone two days ago. The first when turned on by pressing the power button. the small sensor that above the F keys were all lit and when I pressed them Flash and it stay on again. Also the above the mouse/Touchpad sensor and satel

  • NFSU has quit unexpectedly

    "NFSU has unexpectedly" is the message I get after playing for about 1 minute. I saw many other people with the same complaint on other forums but you have not seen it mentioned on the forums of Palm. Despite what is a 3rd party app, I write here bec

  • Upgrade graphics card (for Compaq Presario SR1921il [product number: RC566AA])

    as my system is old enough for the new technology, I have doubts about the graphics card, it can support... Make my system of support of these base maps, AMD/ATI HD 5450 512 MB DDR2 graphics card, Sapphire AMD/ATI Radeon HD 5450 1 GB DDR3 Graphics Ca

  • Help photo transfer

    I have a simple motorolla krazr cell, all I want is to know how to transfer pictures on my Toshiba lap top.  I managed to download the Motoralla software on top of the Tower, but I've been at this for 3 h and can not understand. Help, please...

  • BlackBerry smartphones a form any of perhaps of virus, which came with the update

    I'm not technology savvy person most as it is, however, I received a message about a update available for my BB Tour. I accepted, and everything seemed to go well, until an hour ago. After every SMS, MMS, phone call, an appearance jazz singer sings t