VMware Cloud Community
nmanm0305
Enthusiast
Enthusiast
Jump to solution

Set VM Restart Priority

Hello. Im somewhat new to PowerCLI.  Im looking for a way to set the VM restart priority for 1000+ machines (spread across multiple clusters and vCenters). The priority is based on the first two letters of a machine's name.

For example a machine named GPmymachine01 is considered a production machine and its restart priority would be set as high. Any other G*mymachine name is considered a test machine and its restart priority would be set as low.

I've considered setting each machine individually (e.g. Set-VM mymachine -HARestartPriority High), but doing that with 1000+ machines in a dynamic environment would be time intensive and not necessarily reusable.

I think I need some type of IF statement, but I'm not very familiar with coding/scripting techniques to know how to accomplish this. Any help is very much appreciated. Something like this?.....

Get-VM | {

  if ( vm name starts with GP ) {# set restart priority High}

  else {# set restart priority low}

}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

A simple solution that uses RegEx matching could be something like this.

Do you also have VM that do not start with 'G'? And what priority do they need?

$vms = Get-VM

$vms | where{$_.Name -match '^gp'} | Set-VM -HARestartPriority High -Confirm:$false

$vms | where{$_.Name -match '^g(?!p)'} | Set-VM -HARestartPriority Low Confirm:$false


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

A simple solution that uses RegEx matching could be something like this.

Do you also have VM that do not start with 'G'? And what priority do they need?

$vms = Get-VM

$vms | where{$_.Name -match '^gp'} | Set-VM -HARestartPriority High -Confirm:$false

$vms | where{$_.Name -match '^g(?!p)'} | Set-VM -HARestartPriority Low Confirm:$false


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

0 Kudos
nmanm0305
Enthusiast
Enthusiast
Jump to solution

Wow, thank you for the quick reply! I just tested your examples and they are perfect.

I do have VMs that do not start with 'G'

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And should their restart priority be changed as well, or left as is?


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

0 Kudos
nmanm0305
Enthusiast
Enthusiast
Jump to solution

Left as is for now; their naming schemes dont lend themselves to easy grouping. Thanks again!

0 Kudos