VMware Cloud Community
byogi
Contributor
Contributor

Possible Bug when using Powercli to assign autostartup group on VMware 7u3

 

I'm running into an issue on in all my environments, where the second VMs Start Order is pushed to last. But when the script runs, the output does say it has set the correct order.

 

 

I'm using the following,  modified version of LucD's script.

 

$startDelaySeconds = "240"

$stopDelaySeconds = "240"

$ENV = 'US_01'

$csvFile1 = "../../csv/cluster-$ENV.csv"

$csvFile2 = "../../csv/esxvmslist-$ENV.csv"

$delay = "240"

#Import vm name and ESxi name from csv files

$csvesxcluster = Import-Csv $csvFile1

$csvVMs = Import-Csv $csvFile2

ForEach ($esxcluster in $csvesxcluster) {

get-datacenter $esxcluster.clustername |get-vmhost | Get-VMHostStartPolicy | Set-VMHostStartPolicy -Enabled:$true -StartDelay $startDelaySeconds -StopDelay $stopDelaySeconds -WaitForHeartBeat:$true -Confirm:$false

$esxStart = get-datacenter $esxcluster.clustername |get-vmhost




}

ForEach ($vm in $csvVMs) {

# Where each $vm is a VM name

if ( $vm.group -eq 1 ) {

Get-VM $vm.name | Get-VMStartPolicy | Set-VMStartPolicy -StartAction PowerOn -StartOrder 1

}

elseif ( $vm.group -eq 2 ) {

Get-VM $vm.name | Get-VMStartPolicy | Set-VMStartPolicy -StartAction PowerOn -StartOrder 2 -StartDelay ( 2*$delay)

}

elseif ( $vm.group -eq 3 ) {

Get-VM $vm.name | Get-VMStartPolicy | Set-VMStartPolicy -StartAction PowerOn -StartOrder 3 -StartDelay ( 3*$delay)

}

elseif ( $vm.group -eq 4 ) {

Get-VM $vm.name | Get-VMStartPolicy | Set-VMStartPolicy -StartAction PowerOn -StartOrder 4 -StartDelay ( 4*$delay)

}

}

 
 
 
during  script runs it spits the following output:

VirtualMachineId : VirtualMachine-vm-123456
VMId : VirtualMachine-vm-123456
VM : VM002
VirtualMachineName : VM002
VmHostId : HostSystem-host-9876543
StartAction : PowerOn
StartDelay : 480
StartOrder : 2
StopAction : PowerOff
StopDelay : 240
WaitForHeartbeat : True
IsStartDelayInherited : False
IsStopActionInherited : True
IsStopDelayInherited : True
IsWaitForHeartbeatInherited : True
Uid : /VIServer=ad\user@vcenter7.test.com:443/VMHost=HostSystem-host-9876543/VMStartPolicy=VirtualMachine-vm-123456/
ExtensionData : VMware.Vim.AutoStartPowerInfo

 

# But  when I verify I get the following:

Get-vm -Name "VM002" | Get-VMStartPolicy | select VM,StartAction,StartOrder

VM StartAction StartDelay StartOrder
-- ----------- ---------- ----------
VM002 PowerOn 480 6

 

Startorder 6 refers to sixth VM (Last).

 

Did I miss something , or do we have a bug in PowerCLi implementation for autostartup.

Labels (2)
Reply
0 Kudos
7 Replies
MerlevedeN
Enthusiast
Enthusiast

I think you are comparing strings with numbers.

if ( $vm.group -eq 1 )

Try converting the $vm.group to an int

if ( [INT]$vm.group -eq 1 ) { 

 

LucD
Leadership
Leadership

What do you have in the esxvmslist-$ENV.csv file?

A VM's startorder is relative to the other VMs in the list.
It can be that a VM's startorder is changed if you insert a new VM before the old VM, the order value of that old VM can change.
See also the StartOrder description in the 
AutoStartPowerInfo obect

On a side note, PowerShell has implicit conversion based on the type of the left-hand side operand.
No need to explicitly use casting.


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

Reply
0 Kudos
byogi
Contributor
Contributor

Thanks for the responses:

 

Contents of "esxvmslist-US_01.csv":

esxhost,name,group
esxi01.test.com,VM001,1
esxi01.test.com,VM002,2
esxi01.test.com,VM003,2
esxi01.test.com,VM004,3
esxi01.test.com,VM005,3
esxi01.test.com,VM006,4

 

I will review the docs provided.

 

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, the fact VM002 ends up in position 2 seems to be due to the entries in that CSV.
After the 2nd line VM002 will be in place 2.
Then after line 3 (VM003), it will move to place 3 since yoiu insert VM003 on place 2.
And so on, resulting in VM002 ending up in place 6


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

Reply
0 Kudos
byogi
Contributor
Contributor

 I misunderstood the premise. My bad

This implies, that start order is per VM and not per Group ? 

If I have to use this per Group then I have to use the option "UnspecifiedStartOrder"

 

 

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, that is per VM, and make sure to take care when inserting a VM in the order.
Then other VMs will shift.

Not sure what you mean by group?
Are you sure you are not thinking of the HA VM restart feature, where you can define groups.
There you can specify which group should be started before or after another group.


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

Reply
0 Kudos
byogi
Contributor
Contributor

No, it is not HA VM restart. These are edge environments with one ESXi.

I started with a wrong premise , I was under the impression I could use the "startorder" for a defined group of VMs too.

Get-VMHost esxi01.test.com|Get-VM |Get-VMStartPolicy | select VM,StartAction,StartOrder |Sort-Object StartOrder

VM StartAction StartOrder
-- ----------- ----------
VM001 PowerOn 1
VM003 PowerOn 2
VM004 PowerOn 3
VM005 PowerOn 3
VM006 PowerOn 4
VM002 PowerOn 6

 I have five other environments with even more VMs and  I got thrown off as it was always the second VM.

Thanks for clarifying this .

Reply
0 Kudos