Currently this script outputs to an HTM file with the computername in cell 1, all the servicenames in cell 2, and all the status in cell 3. What I would like is to split it up so each line has the computer name, 1 service, and 1 status.
Function servicestatus ($serverlist, $serviceslist)
{
foreach ($machineName in $serverlist)
{
foreach ($service in $serviceslist)
{
$serviceStatus = get-service -ComputerName $machineName -Name $service
if ($serviceStatus.status -eq "Running") {
Write-Host $machineName `t $serviceStatus.name `t $serviceStatus.status -ForegroundColor Green
$svcName = $serviceStatus.name
$svcState = $serviceStatus.status
Add-Content $report ""
Add-Content $report " $machineName"
Add-Content $report " $svcName"
Add-Content $report "$svcState"
Add-Content $report ""
}
elseif ($serviceStatus.status -eq "Stopped")
{
Write-Host $machineName `t $serviceStatus.name `t $serviceStatus.status -ForegroundColor Yellow
$svcName = $serviceStatus.name
$svcState = $serviceStatus.status
Add-Content $report ""
Add-Content $report "$machineName"
Add-Content $report "$svcName"
Add-Content $report "$svcState"
Add-Content $report ""
}
else
{
Write-Host $machineName `t $serviceStatus.name `t $serviceStatus.status -ForegroundColor Yellow
$svcName = $serviceStatus.name
$svcState = $serviceStatus.status
Add-Content $report ""
Add-Content $report "$machineName"
Add-Content $report "$svcName"
Add-Content $report "$svcState"
Add-Content $report ""
}
}
}
}