Push-Installing an OpsMgr Agent Through a Script

In some cases, deploying Operations Manager (OpsMgr) agents through the console (i.e., “push-install”) is not possible. For example, some organizations mandate that every software deployment, including the various agents (virus-scanner, backup, monitoring, etc.), must be deployed through centralized processes. This can include deploying using Systems Center Configuration Manager.

In this blog post, I will demonstrate how to use the OpsMgr PowerShell cmd-let to deploy an agent through a script and still retain the advantages of a push-installation.

Push Versus Manual Installation

A “push” agent installation is done through the administrator console; in contrast, a manual installation is often done by either installing from the OpsMgr installation media or running the momagent.msi package from one of the management servers (or copying the directory somewhere else).

One of the biggest drawbacks of the manual installation method is that it prevents you from managing the agents from the console. You cannot change the Primary Management Server that the agent reports to, repair, or uninstall the agent from the console. Of course, if your organization mandates that you deploy software from a centralized location, the mandate probably extends to uninstalling as well; therefore, you may not have an incentive to remotely manage agents for those two cases.

The figure below shows the options that are not available (i.e., greyed out) when an agent is installed manually (right figure) versus the push method (left figure):

 

image      image

 

In the case of changing the agent assignment, however, or repairing the agent as part of troubleshooting, being able to do so from the console is still valuable.

Install-SCOMAgent cmd-let

You can use a PowerShell cmd-let called “Install-SCOMAgent” to install an agent from a script that results in a “push” installation.

Param(

[string]$agent

)

Import-Module operationsmanager

New-SCOMManagementGroupConnection

$PrimaryMS = Get-SCOMManagementServer –Name <fqdn_of_Management_Server>

install-scomagent –dnshostname $agent –PrimaryManagementServer $PrimaryMS

 

  • The script starts by defining the parameter $agent, which will be the FQDN of the agent we want to deploy to.
  • Then the OpsMgr PowerShell module is loaded (Import-Module operationsmanager).
  • Next, the script will connect to the Management Group (New-SCOMManagementGroupConnection).
  • Then we define the Primary Management Server for the agent to report to. Note that you could change this to a parameter to be passed to the PowerShell command, much like that agent name. I chose not to for two reasons:
    • To avoid mixing the agent and management server name in a command line that runs the script; and
    • To easily change which Management Server the agent reports to from the console once the agent has been deployed.

The picture below shows the PowerShell script and the command line with the agent parameter.

image

Notes on Running the Script

A few notes on running this script:

  1. The script needs to run on a server where the operationsmanager PowerShell module is present, such as a Management Server.
  2. I did not specify any accounts to run the installation. The parameter, –ActionAccount, can be used to specify an installation account. If the parameter is not specified (as is the case in this example), the default Management Server Action Account will be used; it needs to have the necessary rights to install software on the agent.

Since the PowerShell script runs from the Management Server, it is essentially a command line version of the console push. However, since it is scripted, it can be deployed through a centralized method such as SCCM, which would provide all the reporting and control sometimes mandated by IT organizations.

Comments welcome!