OpsMgr 2012: Automating Agent Discovery and Deployment with PowerShell [sample script]

A couple of days ago I blogged about how to identify computers without an Operations Manager 2012 (OpsMgr) agent in your Active Directory in  OpsMgr 2012: Identifying Computers in Active Directory without an OpsMgr Agent Installed, which is an important task in any enterprise to ensure you have full visibility into your infrastructure and applications. Once you’ have identified the gap, the next step is getting an OpsMgr agent installed quickly (and preferably automatically). This short post will present the next step in the process…installing the OpsMgr agent on computers identified with the AD agent gap sample script.

In this post:

  • Considerations
  • Sample Script
  • Tracking Results in OpsMgr
  • Additional Resources

Considerations

There are a few things to consider before you try to automate push-installation, including:

  • Permissions – Make sure the management server action account is actually a local administrator on the managed computers, or agent installation will fail.
  • Connectivity – The push-install process involves copying the agent binaries from the primary management server to the target computer, so RPC and SMB connectivity will be required.
  • Management Server – Primary management server has to be provided explicitly. If you have gateways in networks not accessible to all, you’ll need to plan to specify a failover server explicitly. This is a discussion for a later post.

At the end of the day, I was shooting for quick and hands-free. As long as you use the appropriate LDAP filters when identifying computers without an agent (see the script previous poste mentioned above), you should be able to get to a point to automate agent installation if your change management process allows.

Sample Script

This sample script takes a list of computers in a text file (with a header of ServerName) as the input to perform bulk push-installation of OpsMgr agents. You’ll need to update the following values in this script

  • Management Server – Replace “mmsscom01.infrontdemo.local” with the name any management server in your ‘All Management Servers’ resource pool.
  • Input File (Server List) – Replace ‘c:\temp\ADAgentGap.csv’ with the file name and path to your file. File format is pictured here in case you’re not using the script mentioned above (note the ServerName value on line 1)

image

figure 1. Input File for Bulk Agent Install via PowerShell

Note: I like the two step process in the event an org wants someone to perform a quick review of the list rather than just automatically pushing agents. We’ll integrate the two scripts / steps in the process into a single script in the next post.

The sample script below is reasonably well-commented and should be relatively easy to figure out if you have a basic familiarity with PowerShell.

 

 

 Tracking Results in OpsMgr

This script will generate two events in the Task Status view of your OpsMgr Operations console for every server name in the file that can be pinged – the first one for discovery, second one for installation. Note that the task ALWAYS returns Success if the tasks are started successfully. It does not necessarily mean the agent install was successful. That being said, the second event in the task view will show you why the install failed if agent install fails.

image

Both tasks have the same Task Name and Task Description:

image

Task Output – Discovery

The output of the first task (the discovery task) looks like this:

image

Task Output – Successful Agent Install

The output of the agent installation, if successful, looks like this:

image

Task Output – Failed Agent Install

Here is the output of the second event for a failed installation (for which the Task Status still showed ‘Success’. However, you’ll notice the detailed agent installation failure code is shown.

image

And that’s about all there is to it. In the next post, I’ll show you how to take these two scripts and put together automated identification of computers missing agents and automated agent install in a single script.

Additional Resources

Here are some articles related to the MS Private Cloud and System Center 2012 you may find useful.

Orchestrator Jumpstart Series

3 thoughts on “OpsMgr 2012: Automating Agent Discovery and Deployment with PowerShell [sample script]

  1. new2scc

    Hi Pete,

    I’ve just been looking a solution to use Orchestrator to automate SCOM 2012 (SP1) agent install via a script – this may well be exactly what I am looking for.  Can you confirm – does your script replicate an agent ‘Push’ install – ie after an agent is deployed using this script, can it then be managed via the console to automatically receive ayd future updates/UR’s or patches via console in the same way that ‘normal’ pushed agents that are installed via Discovery wizard are able to be automatically updated via pending mgmt?

    I know there a several scripts for command line ‘Manual’ installs, but this isnt of much use for my automation as its the future managability I’m trying to ensure – if I automate a manual agent install then I will end up having to manually revisit those machines as new patches/UR’s are released which is what I want to avoid.

    Any help much appreciated…

  2. new2scc

    Hi Pete,

    Following on from my previous query, I am trying to build an Orchestrator Runbook for automating SCOM agent install using your script which is almost complete and working.

    However just to close the loop on the install process and to try to make it fully automated, is there any way of exposing the ‘Tracking results in Ops Mgr ‘ step, ie checking the task status for Success where the Desciption shows if agent successfully installed or not?

    I was hoping there would be way to mointor OpsMgr via event monitor/custom alert or powershell which could then be included in the Orchestrator runbook so the agent install could be automated end to end, with  the piece included to notify if agent install was successful or failed, instead of having to manually check the console for that last bit of info?

    Do you think this is possible?

  3. Philip George

    I am trying to use this script and it gives me the below error

    Task Status Details

    A module reported an error 0x80070057 from a callback which was running as part of rule “Microsoft.SystemCenter.DiscoverComputersFromAD” running for instance “maz.com” with id:”{51AC83B1-713B-C4D1-ABA7-C6DDA5C23C97}” in management group “Dab_SCOM”.Error Code: -2130771918 (Unknown error (0x80ff0032)).

    Also I am seeing an issue when I run the discovery it does not find the computer.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.