Jaa


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.

Comments

  • Anonymous
    January 01, 2003
    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 referencehere 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!

  • Anonymous
    January 01, 2003
    Thanks for the update, Kyle.  Hopefully others in the community will get some use out of this. -Jonathan

  • Anonymous
    May 29, 2009
    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 FilesSystem Center Operations Manager". I'm wondering how to change the installation path to "D:Program FilesSystemCenter Operations Manager" I know it has something to do with Install-Agent -installAgentConfiguration, im just not sure how to change the installPath.

  • Anonymous
    August 13, 2009
    The comment has been removed

  • Anonymous
    September 14, 2009
    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:TempDiscoveredServers.txt" $InstallAgentConfiguration = New-Object Microsoft.EnterpriseManagement.Administration.InstallAgentConfiguration $InstallAgentConfiguration.InstallPath = "D:Program FilesSystem 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,