Automation

 View Only
Expand all | Collapse all

How to disable or remove VM from VMoverrides ?

nmbgdc

nmbgdcSep 22, 2021 02:03 PM

  • 1.  How to disable or remove VM from VMoverrides ?

    Posted Sep 20, 2021 10:03 AM

    Hi Guys,

     

    I am able to check VM Overrides Rule using the powercli commands and i need to disable them but not able to find the powercli command would appreciate if someone help here ?

    Below commands to check-

    Get-VM | Where-Object {$_.DrsAutomationLevel -eq "Disabled"}

    and set this is the command Set-VM -DrsAutomationLevel Disabled

    what is the command to disable above configuration? 

     

     

    Thanks

     

     

     

     

     

     

     



  • 2.  RE: How to disable or remove VM from VMoverrides ?

    Posted Sep 20, 2021 10:58 AM

    So what is the actual question?
    The Set-VM cmdlet is the one to use with the DrsAutomationLevel parameter.



  • 3.  RE: How to disable or remove VM from VMoverrides ?

    Posted Sep 20, 2021 11:25 AM

    Hi LucD,

    Sorry for the confusion, I want to remove the overrides tick mark from  again the DRS Automation level, below is the screenshot for your reference,  is there any powercli command to remove the tick mark ?

    VM-Overrides.JPG



  • 4.  RE: How to disable or remove VM from VMoverrides ?

    Posted Sep 20, 2021 11:27 AM

    Just to make sure I understand it correctly, you want to remove the VM from the Overrides list?



  • 5.  RE: How to disable or remove VM from VMoverrides ?

    Posted Sep 20, 2021 11:40 AM

    I am looking for either to remove the vm from the list or remove the full list.

    yes you understand correct.



  • 6.  RE: How to disable or remove VM from VMoverrides ?
    Best Answer

    Posted Sep 20, 2021 12:01 PM

    You could do something like this


     wrote:

    I am looking for either to remove the vm from the list or remove the full list.

    yes you understand correct.


    $clusterName = 'cluster'
    $cluster = Get-Cluster -Name $clusterName
    
    $spec = New-Object VMware.Vim.ClusterConfigSpecEx
    
    $cluster.ExtensionData.Configuration.DrsVmConfig |
    ForEach-Object -Process {
        $drsVM = New-Object VMware.Vim.ClusterDrsVmConfigSpec
        $drsVM.Operation = [VMware.Vim.ArrayUpdateOperation]::remove
        $drsVm.RemoveKey = $_.Key
        $spec.DrsVmConfigSpec += $drsVM
    }
    $cluster.ExtensionData.ReconfigureComputeResource($spec,$true)
    


  • 7.  RE: How to disable or remove VM from VMoverrides ?

    Posted Sep 22, 2021 02:03 PM

    Thanks LucD, It works.



  • 8.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2021 02:46 PM

    Hi LucD,

    Your below code works and it remove all the VMs from the Overrides List, but I have got another use case I want to remove the few VM's running on specific host from the cluster VM overrides List is it possible ? if yes can you share the powershell commands..

    $cluster = Get-Cluster -Name $cluster_Name
    $spec = New-Object VMware.Vim.ClusterConfigSpecEx
    $cluster.ExtensionData.Configuration.DrsVmConfig |
    ForEach-Object -Process {
    $drsVM = New-Object VMware.Vim.ClusterDrsVmConfigSpec
    $drsVM.Operation = [VMware.Vim.ArrayUpdateOperation]::remove
    $drsVm.RemoveKey = $_.Key
    $spec.DrsVmConfigSpec += $drsVM
    }

    $cluster.ExtensionData.ReconfigureComputeResource($spec,$true) >$null

     

    Thanks



  • 9.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2021 03:46 PM

    You would need to select the VMs running on that host.
    The rest is the same as with the cluster

    $esxName = 'MyESX'
    
    Get-VMHost -Name $esxName | Get-VM |
    Foreach-Object -Process {
    
    # Same as with the cluster
    
    }
    


  • 10.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 05, 2021 07:07 AM

    Hi LucD,

    Thanks for your reply, 

    This is how I tried this code but its giving the error..

    Get-VMHost 192.168.200.42 | Get-VM |
    >> ForEach-Object -Process {
    >> $drsVM = New-Object VMware.Vim.ClusterDrsVmConfigSpec
    >> $drsVM.Operation = [VMware.Vim.ArrayUpdateOperation]::remove
    >> $drsVm.RemoveKey = $_.Key
    >> $spec.DrsVmConfigSpec += $drsVM
    >> }

    InvalidOperation:
    Line |
    6 | $spec.DrsVmConfigSpec += $drsVM
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | The property 'DrsVmConfigSpec' cannot be found on this object. Verify that the property exists and can be set.
    InvalidOperation:
    Line |
    6 | $spec.DrsVmConfigSpec += $drsVM
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | The property 'DrsVmConfigSpec' cannot be found on this object. Verify that the property exists and can be set.
    InvalidOperation:
    Line |
    6 | $spec.DrsVmConfigSpec += $drsVM
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | The property 'DrsVmConfigSpec' cannot be found on this object. Verify that the property exists and can be set.
    InvalidOperation:

     

    Thanks

     



  • 11.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 05, 2021 07:41 AM

    Looks like you didn't create the $spec content.



  • 12.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 05, 2021 08:20 AM

    Hi LucD,

    below is the script for all cluster VM to get removed from VM Overrides

    $clusterName = 'cluster'
    $cluster = Get-Cluster -Name $clusterName

    $spec = New-Object VMware.Vim.ClusterConfigSpecEx

    $cluster.ExtensionData.Configuration.DrsVmConfig |
    ForEach-Object -Process {
    $drsVM = New-Object VMware.Vim.ClusterDrsVmConfigSpec
    $drsVM.Operation = [VMware.Vim.ArrayUpdateOperation]::remove
    $drsVm.RemoveKey = $_.Key
    $spec.DrsVmConfigSpec += $drsVM
    }
    $cluster.ExtensionData.ReconfigureComputeResource($spec,$true)

     

    Now I am bit confused, with below code which you shared, i have folllow the same way but I am not sure about the $spec content how to create for specific host. 

    $esxName = 'MyESX'

    Get-VMHost -Name $esxName | Get-VM |
    Foreach-Object -Process {

    # Same as with the cluster

    }

     

     

     



  • 13.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 05, 2021 08:46 AM

    The VM Overrides are done on the cluster level, you have to call a Cluster API method.
    But since you want to limit the removal to a specific ESXi node, you will have to filter which VMs to add to the $spec.
    In the following example, I use a Where-clause.

    $clusterName = 'cluster'
    $esxName = 'MyESX'
    
    $cluster = Get-Cluster -Name $clusterName
    
    $spec = New-Object VMware.Vim.ClusterConfigSpecEx
    
    Get-VMHost -Name $esxName | Get-VM |
    Where-Object { $cluster.ExtensionData.Configuration.DrsVmConfig.Key -contains $_.ExtensionData.MoRef} |
    ForEach-Object -Process {
      $drsVM = New-Object VMware.Vim.ClusterDrsVmConfigSpec
      $drsVM.Operation = [VMware.Vim.ArrayUpdateOperation]::remove
      $drsVm.RemoveKey = $_.ExtensionData.MoRef
      $spec.DrsVmConfigSpec += $drsVM
    }
    $cluster.ExtensionData.ReconfigureComputeResource($spec, $true)
    


  • 14.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 08:09 AM

    Hi,

    I get an error:

    Exception calling "ReconfigureComputeResource" with "2" argument(s): "A specified parameter was not correct: spec.drsVm
    ConfigSpec[0].key"
    At C:\Users\hentho\Desktop\removeVMfromOverride.ps1:15 char:1
    + $cluster.ExtensionData.ReconfigureComputeResource($spec, $true)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException



  • 15.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 11:59 AM

    You will have to check what is in $spec.DrsVM.
    Are there any VMs in there?
    Are all these VMs located on the DSC?



  • 16.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 12:36 PM
      |   view attached

    I don't know how to "check what is in $spec.DrsVM"?

    See attached screen shot, that's the VMs I would like to be removed from the VM Overrides list. I want the list to be empty.



  • 17.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 12:56 PM


  • 18.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 01:38 PM

    You mean this? it didn't work, got errors. And it doesn't seem to target a Datastore Cluster, instead the Host Cluster?

    get-vm | Where-Object { $_.DrsAutomationLevel -notlike "AsSpecifiedByCluster" } | set-vm -DrsAutomationLevel AsSpecifiedByCluster -Confirm:$false 

     



  • 19.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 02:03 PM

    This thread is about DRS on a cluster, not about SDRS 



  • 20.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 02:42 PM

    Ah, I confused this thread with the thread "Remove Storage DRS override"


    https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Remove-Storage-DRS-override/m-p/2819678/highlight/true#M98979

     

    Can you please answer me there instead? We have a dialogue there, as you might remember?



  • 21.  RE: How to disable or remove VM from VMoverrides ?

    Posted Oct 04, 2023 03:58 PM

    Done



  • 22.  RE: How to disable or remove VM from VMoverrides ?

    Broadcom Employee
    Posted Apr 11, 2022 03:15 PM

    You can remove the tick from checkbox of DRS automation level with following PowerCLI cmdlets:

    get-vm | Where-Object { $_.DrsAutomationLevel -notlike "AsSpecifiedByCluster" } | set-vm -DrsAutomationLevel AsSpecifiedByCluster -Confirm:$false