Sign up for 1E's newsletter:

OpsMgr Basics: Agent Decommission Powershell Script

Most organisations have a process for decommissioning servers. Some have it documented and implemented as policy, while others take a more ad-hoc approach. Whichever method you employ, when implementing OpsMgr in your environment, you must give some consideration to the decommissioning process within OpsMgr.

As one of the final steps in the decommissioning process, you should log in to the OpsMgr Console and under the Administration tab, Agent Managed you should right click the server in question and select Uninstall. This will remove the OpsMgr agent from the server, and conversely remove the server from OpsMgr. A point of clarification, whilst the agent is removed from OpsMgr, the data is retained in the DataWarehouse database until all data is purged based on your data retention policy.

By including these steps in your Decommission process, it will assist in maintaining a clean console (fewer greyed out agents) and will also assist in reducing management overhead and licensing costs.

If however, you find yourself as I did, faced with the situation were you have several hundred decommissioned servers (in my case over 600) that still exist in OpsMgr, then you have a mammoth cleanup task ahead of you. You could do it the long way and remove them individually from the console but hey, we’re in IT right?! A quick Google search and I found a couple of resources that go some way to doing what I need, but fall short of a one stop solution. SO, when all else fails, do-it-yourself!

Below is a script that will check if the server is truly decommissioned and if so, will remove it from OpsMgr. I don’t take credit for the whole script, as sections have been taken from a script originally created by Satya Vel. His post can be found here. I have made some modifications to his original script to accommodate the ability to read in a text file, verify the server is unavailable and to log the output. Other functionality included is outlined below (taken from the PowerShell script):

# —————————————————————————————- # – Name:    Delete-Agent.ps1                                                            – # – Author:  Dan Kregor (1E – daniel.kregor@1e.com | dan@kregor.net)                     – # – Purpose: This script is designed to remove decommissioned servers for OpsMgr         – # –                                                                                      – # —————————————————————————————- # –                                                                                      – # – NOTES:                                                                               – # – Original Script by Satya Vel | Program Manager | System Center Product Team          – # – More info at <a href=”http://bit.ly/cnjVTL”>http://bit.ly/cnjVTL</a>                                                    – # –                                                                                      – # – Modifications: * Included step to check if server is still active (pingable)         – # –                * Can use SQL, Text File or manually typed source                     – # –                * Included a number of switches to suit different purposes            – # –                                                                                      – # —————————————————————————————- <# .SYNOPSIS This script is designed to remove decommissioned agents from OpsMgr (both the database and console). It will also test that the agent is offline. .DESCRIPTION This script is designed to remove decommissioned agents from OpsMgr (both the database and console). It will also test that the agent is offline .PARAMETER CONFIG Use the -CONFIG switch to set the RMS, SQL Server and Database for both your Lab and Production environments. This information can also be manually updated by editing the Delete-Agent.ini file in the script directory. .PARAMETER FILE Use the -FILE switch to include a text file containing a list of servers. Each server must be on it’s own line. .PARAMETER AGENT Use the -AGENT switch to manually enter the name of 1 or more Agent Managed servers (see examples for more info). .PARAMETER SQL Use the -SQL switch to query the OpsMgr Database for Agents that have not heartbeated prior to 30 days ago. .PARAMETER PROD By default, this script is designed to run against a Test/QA/LAB envirnoment. Use the -PROD switch to run it against your Production environment. .PARAMETER WHATIF Use the -WHATIF switch to run the script without performing the delete action. The script will populate the Log files but not take any action. .EXAMPLE ./Delete-Agent -FILE “C:\temp\servers.txt” Use the -FILE switch to read in a plain text file list of servers. Each server must be on it’s own line within the text file. .EXAMPLE ./Delete-Agent -AGENT server.domain.com Use the -AGENT switch to manually enter the name of a server to be removed from OpsMgr. .EXAMPLE ./Delete-Agent -AGENT server1.domain.com, server2.domain.com You can also enter multiple servers to be removed. Servers must be separated by a comma. .EXAMPLE ./Delete-Agent -SQL Use the -SQL switch to query the OpsMgr Database for Agents that have not heartbeated prior to 30 days ago e.g. If today is August 15th, it will look for Agents that did not heartbeat prior to July 16th .NOTES Removing an agent from OpsMgr does not delete it’s historical data. All historical data is kept in the DataWarehose database for the period of time as determined by your data retention policy. ************************************** IMPORTANT ************************************** Your use of these items is at your sole risk. All items are provided “as-is”, without any warranty, whether express or implied, of accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the items are supported or guaranteed by 1E. 1E shall not be liable for any damages you may sustain by using these items, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages. .LINK More information can be found at: http://opsm.gr #>

You can download the file here. If you like the script or find any issues please provide your feedback in the comments section below.

Press Esc to close

Tagged: ,



Would you like to share your thoughts?

Your email address will not be published.

Please type the characters of this captcha image in the input box


'OpsMgr Basics: Agent Decommission Powershell Script' have 2 comments

  1. November 16, 2010 @ 7:38 am OpsMgr Basics: Agent Decommission Powershell Script - 1E Blog

    [...] OpsMgr Basics: Agent Decommission Powershell Script Most organisations have a process for decommissioning servers. Some have it documented and implemented as policy, while others take a more ad-hoc approach. Whichever method you employ, when implementing OpsMgr in your environment, you must give some consideration Read More… [...]

    Reply

  2. November 16, 2010 @ 8:45 am Tweets that mention OpsMgr Basics: Agent Decommission Powershell Script | 1E Blogs -- Topsy.com

    [...] This post was mentioned on Twitter by Rod Trent and Shay Byrne, Alex de Jong. Alex de Jong said: RT @rodtrent: OpsMgr Basics: Agent Decommission Powershell Script http://bit.ly/96VGO4 [...]

    Reply





Press Esc to close

Copyright © 1E 2014 All Rights Reserved | Terms & Conditions | Privacy Policy