Command Shell Reference
SQL Queries
Welcome to TechNet Blogs Sign in | Join | Help
Discover and install agent using Powershell

Here's an example of how you can run discovery and agent installation using the OpsMgr Command Shell.

$query = New-LdapQueryDiscoveryCriteria -domain <your_domain> -ldapquery "(cn=<target_netbios_name>)"

$discoverycfg = New-WindowsDiscoveryConfiguration -ldapquery $query

$discoveryResults = Start-Discovery -managementServer (get-managementServer) -windowsDiscoveryConfiguration $discoverycfg

Install-Agent -managementServer (get-ManagementServer) -agentManagedComputer $discoveryResults.CustomMonitoringObjects

Note: This will configure the agent to report to the Management Server you are currently connected to while performing this action.

Posted: Sunday, February 24, 2008 11:33 PM by jtalmquist

Comments

Kyle said:

Hey,

I am wondering if there is a way to choose the installation directory on the machine the agent is being deployed to. The Default is "C:\Porgram Files\System Center Operations Manager\". I'm wondering how to change the installation path to "D:\Program Files\SystemCenter Operations Manager" I know it has something to do with Install-Agent -installAgentConfiguration, im just not sure how to change the installPath.

# May 29, 2009 10:20 AM

jtalmquist said:

Good question, Kyle.  I'm not familiar with this installation parameter, but will look into how this is used.

Essentially, this requires some knowledge of creating objects and .Net Framework.  There is a reference here for this class, but I don't see any specific examples of creating an installation path.

If I figure this out, I'll post an update here.  If anyone else had figured out how to use this parameter, please do share!

# May 29, 2009 12:34 PM

Kyle said:

Hello Jtalmquist,

Below is the answer to the problem :)

$rootMS = "servername.domainname"

# 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

# Get the Root Management Server Object

$rootManagementServer = Get-ManagementServer

# Create a variable to hold the domain name

$Domain = "DomainName"

# Create the query that will be used to search for all servers to discover

$LDAPQuery = New-LdapQueryDiscoveryCriteria -domain $Domain -ldapquery "(&(operatingSystem=*Server*)(!cn=server1)(!cn=server2)(!cn=server3)(!cn=server4))"

# Set up a new discovery config

$discoveryConfig =  New-WindowsDiscoveryConfiguration -ldapquery $LDAPQuery

# Start the DIscovery and add results to $DiscoveryResult

$discoveryResult = Start-Discovery -ManagementServer: $rootManagementServer –WindowsDiscoveryConfiguration: $discoveryConfig

$discoveryResult.CustomMonitoringObjects > "C:\Temp\DiscoveredServers.txt"

$InstallAgentConfiguration = New-Object Microsoft.EnterpriseManagement.Administration.InstallAgentConfiguration

$InstallAgentConfiguration.InstallPath = "D:\Program Files\System Center Operations Manager 2007"

# Install the agents that were discovered.

Install-Agent –ManagementServer: $rootManagementServer –AgentManagedComputer: $discoveryResult.CustomMonitoringObjects -InstallAgentConfiguration: $InstallAgentConfiguration

#destroying used object.

$InstallAgentConfiguration.Finalize

Cheers,

# September 14, 2009 1:04 PM

jtalmquist said:

Thanks for the update, Kyle.  Hopefully others in the community will get some use out of this.

-Jonathan

# September 14, 2009 3:06 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker