Basically each day I get a report of servers with a list of services not running. the report will read like ServerName, Services. I want to pull this report in from a csv file and then run the script to see the status of each service listed for the server.
So, If I get a report like Server1, ADobe not running Server1, SQL not running Server2, SQL not running
I am most of the way there but, the loops are running get-service on servers that don't have the service listed. I am trying to find a way to remove the service from the array after each iteration of the loop but, I am finding it hard to do with powershell. There also might just be a better way of doing it all together.
What I have so far is
$servers = Import-Csv -Path 'C:\Users\zada\Documents\New Text Document.csv' | % {$_.Servername}
$services = Import-Csv -Path 'C:\Users\zada\Documents\New Text Document.csv' | % {$_.Servicename}
foreach ($server in $servers) {
Write-Host ***************** getting services list for $server *******************
foreach ($service in $services) {
Get-Service -ComputerName $server -Name $services | Format-Table -Property Status, Name, DisplayName -AutoSize
}
}
The problem is it runs through each server as many times as there are services listed and not all the servers have the same services. I toyed around with running running $service.remove($services) but, that didn't get me anywhere.
Below is an example of how the csv file looks.
Servername Servicename
server1 SQL Server Agent (SQLEXPRESS)
server1 WSUS
server2 Sophos System Protection Service
server3 WindowsRM