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