VMware Cloud Community
delagos
Contributor
Contributor

Powercli to set "manual start" of vm instead of 'automatic startup'?

Been looking for powercli that can be used for moving VM from 'automatic startup' section to 'manual startup'.  Found some stuff regarding using the get and set vmstartpolicy but that doesn't seem to 'move' the vm from auto section to manual section.  Found some info on using the set-vm commandlet with the parameter 'AutomaticStartAction' but that doesn't seem to work or not in use anymore.  Using powercli 6.5.1, latest as of 4/20.  Any ideas?

Tags (1)
0 Kudos
3 Replies
LucD
Leadership
Leadership

Afaik the AutomaticStartAction parameter on the Set-VM cmdlet was only available for Hyper-V.

Are you sure you are talking about PowerCLI.

In vSphere the "start" of VMs is set on the ESXi node level.
To set a specific VM to manual start you could do

$vmName = 'MyVM'

$vm = Get-VM -Name $vmName

$autoSTartMgr = Get-view -Id $vm.VMHost.ExtensionData.ConfigManager.AutoStartManager

$spec = New-Object VMware.Vim.HostAutoStartManagerConfig

$info = New-Object VMware.Vim.AutoStartPowerInfo

$info.Key = $vm.ExtensionData.MoRef

$info.StartAction = [VMware.Vim.AutoStartAction]::none

$info.StopAction = [VMware.Vim.AutoStartAction]::guestShutdown

$info.StartOrder = -1

$spec.PowerInfo += $info

$autoSTartMgr.ReconfigureAutostart($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
delagos
Contributor
Contributor

Got the info about that parameter 'AutomaticStartAction' from this website Configure Virtual Machine Automatic Startup on VMware ESXi – TheITBros .  Apparently the brothers are not to be trusted.  Thanks for the info, I had a suspicion that it may not be something in the vm level.  After looking over your code, I noticed that you used a -1 value for the start order.  I had tried using 0 for the start order value using the vmstartpolicy resulting in an error message.  After your example, I tried -1 instead to see if it returned an error message.  It didn't.  I checked on the gui and it showed that the VM was moved down to the 'manual startup' section!!!

Get-VMStartPolicy -vm somevmname | Set-VMStartPolicy -StartAction none -StartOrder -1   (WORKED!)

Get-VMStartPolicy -vm somevmname | Set-VMStartPolicy -StartAction none -StartOrder 0  (Failed with error message, follows)

Set-VMStartPolicy : 4/21/2017 10:16:01 AMSet-VMStartPolicy   A specified parameter was not correct:

vim.host.AutoStartManager.AutoPowerInfo.startOrder

VMware's docs and examples were not very helpful:

Specify a number to define the virtual machines start order.

No examples of it's use either.  I'd suggest to VMware to note that -1 will move it to manual startup.

Thanks for your help LucD!!!

0 Kudos
LucD
Leadership
Leadership

You find more info on the numbers under the StartOrder property in the API Reference.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos