So I am working on a script that will kick off SCCM updates for newly built VMs. The issue I am running into is that each required update is put into an array with a property called evaluationstate. I only want the script to continue after all updates in the array have an evalstate of either 8 or 13 (success or fail). Not sure how I would accomplish that. Any help would be appreciated
You could do something like this.
Try changing one the Evaluationstate values in the array of objects.
$tab = @(
@{
EvaluationState = 8
},
@{
EvaluationState = 8
},
@{
EvaluationState = 13
},
@{
EvaluationState = 8
},
@{
EvaluationState = 13
}
)
if(-not (($tab.evaluationstate | %{8,13 -contains $_}) -contains $false)){
Write-Host "All are 8 or 13"
}
else{
Write-Host "Not all are 8 or 13"
}
With the same test you could wait in a While-loop.
You didn't specify how that array is populated, and how the evaluationstate property can be updated, so I assume it is done auto-magically.
If not you would need to refresh the content of the array some way or the other.
while(($tab.evaluationstate | %{8,13 -contains $_}) -contains $false){
sleep 5
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this.
Try changing one the Evaluationstate values in the array of objects.
$tab = @(
@{
EvaluationState = 8
},
@{
EvaluationState = 8
},
@{
EvaluationState = 13
},
@{
EvaluationState = 8
},
@{
EvaluationState = 13
}
)
if(-not (($tab.evaluationstate | %{8,13 -contains $_}) -contains $false)){
Write-Host "All are 8 or 13"
}
else{
Write-Host "Not all are 8 or 13"
}
With the same test you could wait in a While-loop.
You didn't specify how that array is populated, and how the evaluationstate property can be updated, so I assume it is done auto-magically.
If not you would need to refresh the content of the array some way or the other.
while(($tab.evaluationstate | %{8,13 -contains $_}) -contains $false){
sleep 5
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. Just to clarify on the While loop, as you have it written if EvaluationState doesn't equal 8 or 13 for all items it will wait 5 secs and check again?
Thanks, I ended up using our syntax with a Do Until loop. Just curious but I noticed the statement used a double negative. Any reason for that?
The expression is build up from the following:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference