VMware Cloud Community
nicholas1982
Hot Shot
Hot Shot

Cant run foreach loop with -RunAsync

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'.

Nicholas
Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

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}}


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

Reply
0 Kudos