I don’t like to clean up very much, but there are certain cases where it really makes fun to clean up. Especially if there a Non-Microsoft product, Powershell and SCOM involved.
In my case a customer decided to replace his Nagios system through SCOM 2012. Cool!!!
Because Nagios also uses an agent for monitoring, one of my first things I did was to write a script to uninstall the Nagios agent from several windows systems.
The idea is to provide a text file containing server names which the script will use to check if the Nagios agent (service) is installed or not. If the service is installed it will uninstall the software. I don’t delete the source files though. I found the sources in the C:\NagiosClient\WindowsClient directory. The “NSClient++.exe” is the actual installation file for the Nagios agent.
The service looks like this…
…and the source files for Nagios like this…
The logic behind the script is like that:
- Define a UNC path to provide a place to store the log file and the server.txt file $serverfile) which has one server name per line.
- $nagiospath defines the directory where the “NSClient++.exe” file is installed on the servers
- $log defines the log file path
- Next the script will read the $serverfile and iterate through each server and checks if the “NSClientpp” service is installed. If this is the case it will call the Invoke-WmiMethod to uninstall the agent remotely. Lastly the time, action and server name is being written to the log file.
And here is the script:
So far I tested the script against Windows 2008 R2 and Windows 2003 servers and it worked.
Start doing some spring cleaning and get rid off Nagios and install SCOM 2012!
You can download the script here.