Check a service on alle servers

 

You can use this script when you want to check multiple servers for the status of a service.

This script gets all the servers from the AD and test is they are available. Next it checks if there is a service with the name backupexecagent* and then displays the status.

The script below is not the most efficient script but it does the trick.

If someone knows how to make this run faster… please let me know.

2 comments

  • I would probably get rid of the second Get-Service command and wrap Get-Service in a try-catch, for example:

    Get-ADComputer -Filter ‘operatingsystem -like “*server*”‘ | Where-Object -Property enabled -EQ “$true” | ForEach-Object {
    if (Test-Connection -ComputerName $server.Name -count 1 -Quiet) {
    try {
    Get-Service -ComputerName $server.name -Name BackupExecAgent* -ErrorAction Stop | Select-Object machinename,status,Displayname
    } catch {
    Write-Verbose “Get-Service failed for $($server.name)”
    }
    }
    }

     
  • Albert van Boerum says:

    Thanks Jaap.

    I had to make some minor adjustments on your input but I got the idea.
    Get-ADComputer -Filter ‘operatingsystem -like “*server*”‘ | Where-Object -Property enabled -EQ “$true” | ForEach-Object {

    if (Test-Connection -ComputerName $_.Name -count 1 -Quiet) {
    try {
    Get-Service -ComputerName $_.name -Name BackupExecAgent* -ErrorAction Stop | Select-Object machinename,status,Displayname
    }
    catch {
    Write-Verbose “Get-Service failed for $($_.name)”
    }
    }
    }

     

Leave a Reply

Your email address will not be published. Required fields are marked *