How to Schedule OpsMgr Discovery and Agent Deployment without AD Integration
By Pete Zerger on 5/9/2009 9:00:17 PM • Rank (1144) • Views 7042
0

0

Scheduled discovery and agent installation was a simple feature we lost in the move to Operations Manager 2007. In reality, it was more or less replaced by AD Integration. But what if you can’t or don’t want to use the AD Integration feature of OpsMgr? Well, you can effectively use Powershell to do this, but it takes some extra work I have not seen clearly illustrated on the Internet.

NOTE: Use caution when updating agent configurations through Powershell. You can inadvertently orphan an agent if you point it to an MS or GW that cannot be reached from it's location on the network.

The Problem

Of all the Powershell samples I’ve seen on the Internet for discovering and deploying OpsMgr agents, all were lacking in several of the same ways that made them less than useful.

  • They assumed agent would report to the RMS
  • The FAIL if multiple management servers exist in your environment
  • The would not allow discovery / installation of multiple agents
  • They lacked any instruction on syntax / updating script for my env.

 

The Solution

In this example, I’ve created  a Powershell script that allows you to discover multiple agents and choose the management server to which they’ll report. I’ve also included syntax assistance. Simply run the script with no parameters and syntax is echoed to the screen. This script can be cut-and-pasted and then scheduled to run on whatever shedule meets your needs.

 

Sample Script

This is a fully functional sample that can be run from anywhere an OpsMgr console / Command Shell is installed. This script needs four parameters: rootMSDomaintargetMS and targetAgent. Run the script with no parameters for syntax guidance. I used the backtick ` operator to wrap lines, so you should be able to cut-and-paste without worrying about line wrap.

#——Begin Sample Script——–

param ($rootMS,$Domain,$targetmS,$targetAgent)
#Checking Root MS parameter
     if ($rootMS -eq $null) {
        Write-Host “”
        Write-Host “SYNTAX:”;
        Write-Host “”
        Write-Host “-rootMS: FQDN of the root management server for the target management group.”;
        Write-Host “Ex: RootManagementServer.fqdn.local”;
        Write-Host “”
        Write-Host “-Domain: The target group.  Use the display name of the group.”;
        Write-Host “Ex: ‘NOC Computers Test”;
        Write-Host “”
        Write-Host “-targetMS: FQDN of the management server for discovery, install and agent mgmt.”;
        Write-Host “Ex: ‘MyMS.fqdn.local’”
        Write-Host “”
        Write-Host “-targetAgent: FQDN of the server on which agent(s) should be installed (wildcards allowed).”;
        Write-Host “Ex: ‘Computer.fqdn.local’”
        Write-Host “”
 exit;
     }

#Initialize the OpsMgr Provider
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client

# Set the location to the root of the provider namespace.
cd OperationsManagerMonitoring::

#create a connection to the Management Group
New-ManagementGroupConnection $rootMS

#change the path
cd $rootMS

#configure query setting based on your -targetMS parameter input
$ldap_query = new-ldapquerydiscoverycriteria -domain $Domain `
 -ldapquery “(sAMAccountType=805306369)(name=$targetAgent*)”

#configure discovery setting
$windows_discovery_cfg = new-windowsdiscoveryconfiguration -ldapquery $ldap_query

# discoveryresults
$discovery_results = start-discovery -managementserver (get-managementserver | `
where {$_.Name -eq “$targetMS”}) -windowsdiscoveryconfiguration $windows_discovery_cfg

#install Agent(s) based on the criteria of your search in the -targetMS parameter
install-agent -managementserver (get-managementserver | where {$_.Name -eq “$targetMS”}) `
-agentmanagedcomputer $discovery_results.custommonitoringobjects

#——End Sample Script——–

Conclusion

I hope you’ve found this helpful. This is a fully functional example we will build on in future posts to include more advanced functionality. Please post any suggestions for additions as a comment to this post.

Comments (2) - Comment RSS
Simon Skinner wrote: on May 10, 2009 03:42 PM
Cool script, this is a problem we ran into when we used to allocate clients in SMS via VB script in GPO's. Licencing of your agents it could be overlooked, is there anyway a log file could also be created to log the installs? Sure we can see install dates but not really a fool proof guide.
curtmcgirt wrote: on May 21, 2012 01:11 PM
when you say "wildcards allowed," do you really mean wildcards plural, or just wildcard singular, meaning *? my dev servers are all named somethingD# or somethingD##. i've always wanted to be able to discover all servers that end in D# or D## and point them at a certain management server, all prod servers that end in P# or P## at another management server.


Who Viewed
Who Reviewed
Categories
Tags
Operations Manager, OpsMgr, Powershell, Automation
Related Pages
Shortened URL
http://tinyurl.com/yh99569

Top Contributors
Featured Members
Pete Zerger
Points: 72684
Level: System Center Expert
Tommy Gunn
Points: 47503
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Andreas Zuckerhut
Points: 30700
Level: System Center Expert
Stefan Koell
Points: 30179
Level: System Center Expert