Automation

 View Only
  • 1.  PowerCLI Maintenance Mode

    Posted Apr 14, 2022 08:43 AM

    Hi Team, 

    I am trying to Put a Host into Maintenance Mode which has both Powered on and Powered off VMs using 

    "Set-VMHost -VMHost $Hostname -State Maintenance " Cmdlet. Host is moving to MM by migrating the Powered ON VMs to another host but its not migrating the Powered Off VMs. But when I try to do the same using GUI, I have an option to migrate the Powered OFF VMs as well to another host in the Cluster. 

    Can we achieve the same via PowerCLI which is to migrate all the VMs both Powered ON and Powered OFF vms to another host and then place into MM.

    Can someone help me in this?



  • 2.  RE: PowerCLI Maintenance Mode

    Posted Apr 14, 2022 08:50 AM

    Did you try the -Evacuate switch?



  • 3.  RE: PowerCLI Maintenance Mode

    Posted Apr 18, 2022 12:22 PM

    That worked, Thanks LucD 



  • 4.  RE: PowerCLI Maintenance Mode

    Posted Apr 19, 2022 07:32 AM

    Hi On my previous reply, I tried it on a different host which was not having powered off VMs. But now when I tried the Evacuate Switch, it puts the host into MM but its not moving the Powered Off VMs to other host.



  • 5.  RE: PowerCLI Maintenance Mode

    Posted Apr 19, 2022 08:52 AM

    Afaik, the cmdlet does not have the option to evacuate powered off VMs.
    For that you have to use the API.
    Something like this

    $esxName = 'MyEsx'
    
    $esx = Get-VMHost -Name $esxName
    
    $timeout = 0    # No timeout
    $evacuatePoweredOffVms = $true
    $spec = New-Object -TypeName VMware.Vim.HostMaintenanceSpec
    $spec.VsanMode = New-Object -TypeName VMware.Vim.VsanHostDecommissionMode
    $spec.VsanMode.ObjectAction = [VMware.Vim.VsanHostDecommissionModeObjectAction]::noAction
    
    $esx.ExtensionData.EnterMaintenanceMode($timeout, $evacuatePoweredOffVms, $spec)
    


  • 6.  RE: PowerCLI Maintenance Mode

    Posted Apr 19, 2022 09:29 AM

    This method worked, Thank you so much 



  • 7.  RE: PowerCLI Maintenance Mode

    Posted Apr 16, 2022 07:15 PM

    Hi.

    I'm using alternate version.

    It will also unmount vmtools from vm on the host.

    $EsxName= "Esx_02"

    $Esx = Get-View -ViewType HostSystem -filter @{"name"="$EsxName"}
    $Vm = Get-View -ViewType VirtualMachine -SearchRoot $Esx.MoRef
    $Vm | Where {$_.Runtime.ToolsInstallerMounted} | % {$_.UnmountToolsInstaller()}
    $spec = New-Object VMware.Vim.HostMaintenanceSpec
    $timeout = 0
    $evacuatePoweredOffVMs = $true
    $taskSDK = $esx.EnterMaintenanceMode_task($timeout,$evacuatePoweredOffVMs,$spec)
    $task = Get-task -status Running | Where {$_.id -match "$($taskSDK.ToString())"}
    Wait-Task -Task $task



  • 8.  RE: PowerCLI Maintenance Mode

    Posted Apr 18, 2022 12:26 PM

    Thank you Macleud