Powershell script to check if a SCOM agent is installed

Hi guys,

Nothing fancy today, just wanted to share with you a Powershell script I wrote today. The script takes one parameter which is a txt file containing a list of servers to check. For example:

Server1

Server2

It then checks if that computer has a SCOM agent or not using the Get-SCOMAgent command. If there is no agent, the script uses Test-Connection to test if the computer is responding to a Ping request.

The output is very clear – Green for installed agent, Red for a computer that answers a Ping request and Yellow for a computer that doesnt.

Like I said, nothing fancy. But useful 🙂

Param ($FileName)
Import-Module OperationsManager
$ComputersArr = Get-Content $FileName
foreach($Computer in $ComputersArr)
{
if (Get-SCOMAgent | where {$_.Name -Like '*' + $Computer + '*'})
{
Write-Host "SCOM agent is installed on " $Computer -ForegroundColor Green
}
Else
{
if (Test-Connection -CN $Computer -Count 1 -BufferSize 16 -Quiet)
{
Write-Host "SCOM agent is NOT installed " $Computer -ForegroundColor Red
}
else
{
Write-Host "Computer " $computer " is not online" -ForegroundColor Yellow
}
}
}

 

[notice]Sorry for the awful code display, still looking for the best plugin for that[/notice]

 

Incoming search terms:

  • powershell is scom agent installed
  • how to check if scom agent is running
  • scomvagent install check
  • scom powershell scripts bank
  • powershell script to check if sccm client is installed
  • powershell check if scom is installed
  • is scom installed
  • how to verify scom agent
  • how to tell if scom is installed
  • how to check scom installation

5 Comments

  1. This is a great script… I am something of a newbie so forgive my naive questions…

    1. Where do I enter the name of the .txt list ?

    2. In the txt list do I just enter one server per line?

    3. I am getting the following error:

    Import-Module : The specified module ‘OperationsManager’ was not loaded because no valid module file was found in any module directory.

    I am not sure if that is because the .txt is not defined OR I need to import a module.

    Thank you very much for sharing this work. Guys like me appreciate the heck out of it.!

    • Hi Rhino,
      The above script is part of function I wrote so you see the script starts with “Param ($FileName)”.
      You can alter this script by removing the first line (Param…) and in the 3rd line just enter the file name. For example:
      $ComputersArr = Get-Content C:\Listofservers.txt

      The list it self should contain only servers names:
      Server1
      Server2
      etc…

      And the error you are getting is because you don’t have this module installed where you trying to run the script from. During the installation of the OperationsManager console the setup also places this module in the PowerShell default folder. Your solution is either install the OMConsole on the client you’re trying to run the script from or by running the script from the server it self.

      Good luck and let me know how that works out for you!

      • Dude you are a ninja.

        Outstanding! I should have thought of that. I am curious however, how would I make the parameter work? I am trying to take my meager ps skillset to the next level…

        Thanks in advance,
        Rhino

        • You can write a function with PowerShell to perform the action you want.
          For example, you can create a script with a ‘Main’ function that prompts the user (who’s running the script) asking him for the desired action – something like:
          Please choose from the following:
          1 – Get a list of installed agents
          2 – Install a new agent

          Each of the following choices will trigger a PS function.

          You simply write the ‘Main’ function on the script, and each function starts with ‘Functin InstallAgent()’.

  2. Hi

    How can i write the output of this command into a file.

    I’m trying the Out-File command, it creates a blank file only.

    Thank you in advance

What do you think about this post?