VMware Cloud Community
kwg66
Hot Shot
Hot Shot
Jump to solution

Get-Random

I am using this parameter to randomly select hosts in a cluster, but I want to be able to exclude a specific host, how would I do this?

Here is the string:

$esx = Get-VMHost -Location $vccluster | Get-Random

What code would I append Get-Random with to exclude a specific host which I have defined as a variable $VMHost 

Thanks

 

 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try with

$esx = Get-VMHost -Location $vccluster | where{$_.Name -ne $VMHost} | Get-Random


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 with

$esx = Get-VMHost -Location $vccluster | where{$_.Name -ne $VMHost} | Get-Random


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

0 Kudos
kwg66
Hot Shot
Hot Shot
Jump to solution

Thanks LucD - on the Get-Random, how would one create an exception to this to exclude a specific host?   

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not sure what you mean.
The exception is done via the Where-clause, unless you mean something else.
The Get-Random cmdlet doesn't have an Exclude option


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

0 Kudos
kwg66
Hot Shot
Hot Shot
Jump to solution

Sorry - working on too many things at once, you already answered this it is what the post was about hahaha not sure what I was thinking.... if at all 🙂 

0 Kudos