PowerCLI

 View Only
  • 1.  Get-Random

    Posted Feb 27, 2024 06:17 PM

    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

     

     

     



  • 2.  RE: Get-Random
    Best Answer

    Posted Feb 27, 2024 06:28 PM

    Try with

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


  • 3.  RE: Get-Random

    Posted Mar 15, 2024 07:18 PM

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



  • 4.  RE: Get-Random

    Posted Mar 15, 2024 07:27 PM

    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



  • 5.  RE: Get-Random

    Posted Mar 15, 2024 07:42 PM

    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