1 Reply Latest reply on Dec 4, 2017 6:02 AM by LucD

    Cant run foreach loop with -RunAsync

    nicholas1982 Hot Shot

      Trying to test hostprofile compliance on all hosts at once for some odd reason cun't seem to run this async. In the GUI there is one button on for the hostprofile to check compliance on all hosts its attached to, ideally I would like to hot that but otherwise is there another way I could run against all at once?

       

       

      foreach ($esxiserver in $esxiservers){

      Test-VMHostProfileCompliance -VMHost $esxiserver -RunAsync

      }

       

      Test-VMHostProfileCompliance : A parameter cannot be found that matches parameter name 'RunAsync'.

        • 1. Re: Cant run foreach loop with -RunAsync
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Not sure why they left out the RunAsync on that cmdlet, but in the corresponding API method you can do it.

          Something like this

           

          $profName = 'Test'

           

          $hp = Get-VMHostProfile -Name $profName

           

          $id = @()

          Get-Cluster -Name Cluster1 | Get-VMHost | %{

              $id += $hp.ExtensionData.CheckProfileCompliance_Task($_.ExtensionData.MoRef)

          }

           

          while(Get-Task -Id $id | Where{$_.State -eq 'running'}){

              sleep 5

          }

           

          Get-Task -Id $id |

          Select Name,Id,@{N='ComplianceStatus';E={$_.Result.ComplianceStatus}}