Here is the my code of my function :
function RetrieveServiceStatus ($cptlist, $service) {
#function var
$servicestatus = @()
$cptlist | ForEach-Object {
$serviceobj = Get-Service -DisplayName $service -ComputerName $_
$statusrow = New-Object PSObject
$statusrow | Add-Member -Type NoteProperty -Name Computer -Value $_
$statusrow | Add-Member -Type NoteProperty -Name Status $serviceobj.Status
$statusrow | Add-Member -Type NoteProperty -Name service -Value $service
$servicestatus += $statusrow
}
$servicestatus
}
This function is called within a loop, when i call this function everything works well... Except the last line, which is supposed to show me my result. The result is showing up on the next occurence of the loop. Do you have any idea why?