MilesLogan
asked on
Verify if service is running on a list of servers
Hi EE
Does anyone have a script to share or can help me modify the one below?
I need the script to check a txt file and get me the status of a service on the list of servers.
The script below works but I need it to also output if a server on the list is not online .
Does anyone have a script to share or can help me modify the one below?
I need the script to check a txt file and get me the status of a service on the list of servers.
The script below works but I need it to also output if a server on the list is not online .
$Computers = Get-Content C:\PS\servers.txt
$output = @()
foreach ($c in $Computers)
{
$services = Get-Service *ServiceName* -ComputerName $c | Select Name, Status
if ($services -eq $null)
{
$cinfo = New-Object PSObject
$cinfo | Add-Member -MemberType NoteProperty -Name "MachineName" -Value $c
$cinfo | Add-Member -MemberType NoteProperty -Name "Name" -Value $null
$cinfo | Add-Member -MemberType NoteProperty -Name "Status" -Value "No ServiceName present"
$output += $cinfo
}
else
{
foreach ($s in $services)
{
$cinfo = New-Object PSObject
$cinfo | Add-Member -MemberType NoteProperty -Name "MachineName" -Value $c
$cinfo | Add-Member -MemberType NoteProperty -Name "Name" -Value $s.Name
$cinfo | Add-Member -MemberType NoteProperty -Name "Status" -Value $s.Status
$output += $cinfo
}
}
}
$output | Out-GridView
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER