In part 1, we demonstrated how to update the proxy agent for a group of managed SNMP-enabled devices. The difficulty in using the solution presented is part 1 is in using the get-agent cmdlet to retrieve the potential proxy agent to pass to set-proxyagent, which only returns agents; no management servers are presented. Using the get-managementserver cmdlet in it's place results in a failure because it does not return the right object to pass to set-proxyagent.
If I want to use a management server as the proxy for multiple network devices, the script below will allow you to submit a wildcard filter based on device IP address to update the proxy agent for all SNMP-enabled devices matching the filter, and assign a managment server as the proxy agent.
Thanks to Marco Shaw for a critical assist in working out the code to allow passing wildcard for the -deviceName parameter.
INSTRUCTIONS FOR USE
Cut-and-paste the script below into Notepad, and save as updateproxyagentMS.ps1. Script should run from any computer with OpsMgr Console and Powershell installed.This script will load the OpsMgr Powershell snap-in and connect to your Management Group. SYNTAX
The script accepts the following 3 required parameters. Run with no parameters to view syntax help.
-rootMS: FQDN of the root management server for the target management group.
Ex: 'RootManagementServer.fqdn.local'
-proxyAgent: Management Server that will serve as the proxy agent
Ex: ‘ms1.contoso.com'
-deviceName: IP address or IP wildcard range.
Ex: ‘192.168.1*’
SAMPLE SCRIPT
Here is the sample script. You should be able to cut-and-paste this one with no worries about line wrap.
#-----------Begin Sample Script--------------
param($rootMS,$proxyAgent,$deviceName)
#Echo syntax if -rootMS parameter is NULL
if ($rootMS -eq $null) {
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 "-proxyAgent: Agent-managed computer that will serve as the proxy agent";
Write-Host "Ex: ‘dc.contoso.com";
Write-Host ""
Write-Host "-deviceName: IP address or IP wildcard range.”;
Write-Host "Ex: ‘192.168.1*’”;
Write-Host ""
exit;
}
#connect to mgmt group
$ServerName=$rootMS
add-pssnapin Microsoft.EnterpriseManagement.OperationsManager.Client ;
set-location OperationsManagerMonitoring:: ;
new-managementGroupConnection -ConnectionString:$serverName;
set-location $ServerName;
$mg=new-managementgroupconnection $rootMS
$mgname=$mg.managementgroup
$admin=$mgname.getadministration()
#Retrieve management server that will serve as proxy agent
$crit=new-object microsoft.enterprisemanagement.administration.managementservercriteria("Name = '$proxyAgent'")
$server=$admin.getmanagementservers($crit)[0]
#Retrieve all our monitored network devices
$netdevices=$admin.getallremotelymanageddevices()
#Sets the proxy of all network devices to the specified proxy server
$coll= new-object "system.collections.generic.list``1[[Microsoft.EnterpriseManagement.Administration.RemotelyManagedDevice, Microsoft.EnterpriseManagement.OperationsManager, Version=6.0.4900.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]"
for($i=0;$i -lt $netdevices.count;$i++){
if($netdevices[$i].ipaddress -like "$deviceName"){$coll.add($netdevices[$i])}
}
$new_netdevices= new-object "System.Collections.ObjectModel.ReadOnlyCollection``1[[Microsoft.EnterpriseManagement.Administration.RemotelyManagedDevice, Microsoft.EnterpriseManagement.OperationsManager, Version=6.0.4900.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" (,$coll)
$admin.setproxyagent($new_netdevices,$server)#-----------End Sample Script--------------
Conclusion
Hope you find this one useful. Please submit feedback as a comment on this post.
|
|
|
|
Thank you for your rating!
|
Share This |
Views: 307 :: Rank: (127) |
Filed In: Blog, Operations Manager, Powershell |
242 days ago |
|
|
|
|
|
|
|
|