$GetNamespace = Get-WmiObject -Class “MIIS_RunHistory” -Namespace root\MicrosoftIdentityIntegrationServer | Select-Object -First 9 $MaAgentError = @() foreach($Namespace in $GetNamespace) { if($Namespace.RunStatus -eq "success"){ $MaAgentOK = "Everything allright" } else { foreach($Namespace in $GetNamespace) { $MaAgentError += $Namespace.MaName+" "+$Namespace.RunProfile.ToString()+" "+$Namespace.RunStatus } $MaAgentError break } } if($MaAgentError.Count -eq 0) { $MaAgentOK }