VMware Cloud Community
chakoe
Enthusiast
Enthusiast
Jump to solution

Modify StartDelay for multiple VMs

Hi and good morning,

here i am again with a new question Smiley Happy

I want to set the StartDelay to 10 seconds on multiple VM´s.

I think I have to use sometihng like

Get-VM -Name <vmname> | Set-VMStartPolicy -StartDelay 10000

But this doesn´t work... Smiley Sad

Thx for any help

Chakoe

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are looking at the Boot Delay option, not the Startup delay.

That one lives in the VMX file and can be changed like this (value in milliseconds).

$value = "5000"

$vm = Get-VM <vmname> | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value
$vm.ReconfigVM_Task($vmConfigSpec)

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Startdelay is expressed in seconds.

And you set it like this

 Get-VM <vm-name> | Get-VMStartPolicy | Set-VMStartPolicy -StartDelay 10

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hi,

your scipt returns no error, it returns an OK-Message

VM StartAction StartDelay StartOrder

-- -


-


-


vmname None 10

The VirtualCenter posts a message like:

Reconfigure AutoStart Manager Target=vmhost Status=completed

But when i check the vm ( Edit Settings, Options, BootOptions) The PowerOn Boot delay is set to 0

It seems that the script reports no error but does nothing?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Btw, you use the same logic to enable/disable the start policy on the hosts.

Get-VMHost -Name <hostname> | Get-VMHostStartPolicy | Set-VMHostStartPolicy -Enabled:$true

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are looking at the Boot Delay option, not the Startup delay.

That one lives in the VMX file and can be changed like this (value in milliseconds).

$value = "5000"

$vm = Get-VM <vmname> | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value
$vm.ReconfigVM_Task($vmConfigSpec)

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hey,

thanks....works fine!

Greets

Chakoe

0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hi,

i stil have a little problem with this, because i cannot modify multiple vm´s...

If i change the value for the target-vm from vmname1 to vmname* (to use all vm´s beginning with "vmname" ), the script fails with the folowing error:

Method invocation failed because [http://System.Object[|http://System.Object[]] doesn't contain a method named 'ReconfigVM_Task'.

At :Row:10 Char:19

+ $vm.ReconfigVM_Task &lt;&lt;&lt;&lt; ($vmConfigSpec)

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To change multiple VM's you can change Luc's script into:

$value = "5000"

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value

Get-VM <vmname> | Get-View | ForEach-Object {
  $_.ReconfigVM_Task($vmConfigSpec)
}

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
pmerkel
Contributor
Contributor
Jump to solution

Is there a cmd to retrieve the current value of the bootdelay?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is no PowerCLI cmdlet that returns that property.

But you can easily get it like this.

In PowerCLI 4.1

Get-VM | Select Name,@{N="BootDelay";E={$_.ExtensionData.Config.BootOptions.BootDelay}}

or with the New-VIProperty cmdlet

New-VIProperty -Name "BootDelay" -ObjectType VirtualMachine -Value {
	param($vm)
	
	$vm.ExtensionData.Config.BootOptions.BootDelay
}  -BasedOnExtensionProperty "Config.BootOptions"

Get-VM | Select Name, "BootDelay"

When you're not yet migrated to PowerCLI 4.1, you can do

Get-VM | Select Name,@{N="BootDelay";E={($_ | Get-View).Config.BootOptions.BootDelay}}

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
mazdajai
Contributor
Contributor
Jump to solution

I am trying to read the machine from a text file to but I seem to be getting synatx errors.

Any help is appreicated.

$value = "6500"

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value

Get-Content -Path D:\abc.txt | `
ForEach-Object (Get-VM -Name $_).ReconfigVM_Task($vmConfigSpec)
}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try it like this

$value = "6500"

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value

Get-Content -Path D:\abc.txt | %{
   (Get-VM -Name $_).Extensiondata.ReconfigVM_Task($vmConfigSpec)
}


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

0 Kudos
mazdajai
Contributor
Contributor
Jump to solution

Thanks It worked!

Can you explain why ForEach-Object is not needed? And .Extensiondata is needed?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry for that, the % is an alias for the Foreach-Object cmdlet.

You can check with

Get-Alias %


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

0 Kudos