VMware Cloud Community
Evilence
Contributor
Contributor
Jump to solution

Powering on VMs with specific notes

Greetings,

I am trying to create powerCLI script, that powers on virtual machines with specific notes.

For example, after disaster or maintenance, only VM that has "HA" should be powered. Is it possible to implement this via powerCLI?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect the Start-VM doesn't hang but that the cmdlet waits for the VM to be started, the Start-VM cmdlet runs by default in sync mode. In other words, it waits till the guest is started.

If you prefer not to wait you can do

Get-VM | where {$_.Note -match "HA"} | Start-VM -Confirm:$false -RunAsync

But beware that this will create a startup storm of VMs which can put a heavy load on your ESX(i) servers.

You can combine all this as follows

Get-Cluster $clustername | Get-VM | where {$_.Note -match "HA"} | Start-VM -Confirm:$false -RunAsync


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VM | where {$_.Notes -match "HA"} | Start-VM -Confirm:$false


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

Evilence
Contributor
Contributor
Jump to solution

Thank you,

That works just great, but unfortunately only for one WM. After that, script hangs Smiley Happy

I am trying to perform following:

$vms = get-vm -Location (get-cluster $clustername)

To get all VMs in cluster,

and then

ForEach ($vm in $vms)
{
$vm | where {$_.Notes -match "HA"} | Start-VM -RunAsync
}

But still, only one WM powers on. How can I perform this check on every machine in the cluster?

Sorry for such newbie question Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect the Start-VM doesn't hang but that the cmdlet waits for the VM to be started, the Start-VM cmdlet runs by default in sync mode. In other words, it waits till the guest is started.

If you prefer not to wait you can do

Get-VM | where {$_.Note -match "HA"} | Start-VM -Confirm:$false -RunAsync

But beware that this will create a startup storm of VMs which can put a heavy load on your ESX(i) servers.

You can combine all this as follows

Get-Cluster $clustername | Get-VM | where {$_.Note -match "HA"} | Start-VM -Confirm:$false -RunAsync


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

0 Kudos
Evilence
Contributor
Contributor
Jump to solution

Thank you for such quick response and help.

It works like a charm Smiley Happy

0 Kudos