Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Discover & Add Network Devices via PS

57 views
Skip to first unread message

Sakkieg

unread,
Oct 28, 2008, 6:30:00 AM10/28/08
to
II am trying to discover and add network devices via powershell on a
schedule. I use the following script;

#######Start######

$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'
$DDC = New-DeviceDiscoveryConfiguration -monitoringclass $networkdeviceclass
-fromipaddress 10.10.10.10 -toipaddress 10.10.10.10
$encoding = new-object System.Text.UnicodeEncoding
$encodedCommunityString = $encoding.GetBytes("public")
$DDC.ReadOnlyCommunity =
[System.Convert]::ToBase64String($encodedCommunityString)
$ManagementServer = get-managementServer | where {$_.IsRootManagementServer
-eq $True}
#Write-Host $ManagementServer.name
$DiscResults = start-discovery -ManagementServer: $ManagementServer
-DeviceDiscoveryConfiguration: $DDC
$DiscResults | select-object -expand custommonitoringobjects
$Proxy = get-managementServer | where-object {$_.Name -eq
"machine.domain.co.za"}
#Write-Host $proxy.name
add-remotelymanageddevice -proxyagent $Proxy -device
$discovery_results.custommonitoringobjects

###########End###########

I'm having trouble with the last line;
add-remotelymanageddevice -proxyagent $Proxy -device
$discovery_results.custommonitoringobjects

######Error Start#######

Cannot bind parameter 'ProxyAgent'. Cannot convert
"Microsoft.EnterpriseManagement.Administration.ManagementServer" to
"Microsoft.EnterpriseManagement.Administration.AgentManagedComputer".

#######Error End ########

The orginal script read;
$agent = get-agent | where-object {$_.Name -eq "THUNDER.odyssey.com"}

I replaced that with;
$Proxy = get-managementServer | where-object {$_.Name -eq
"machine.domain.co.za"}

I need the RMS to be the proxy agent for these network devices.

This script was sources from SCOM Unleashed.

Any help would be appreciated.

Marco Shaw [MVP]

unread,
Oct 28, 2008, 8:22:48 AM10/28/08
to

> The orginal script read;
> $agent = get-agent | where-object {$_.Name -eq "THUNDER.odyssey.com"}
>
> I replaced that with;
> $Proxy = get-managementServer | where-object {$_.Name -eq
> "machine.domain.co.za"}

I don't have access to a large enough environment to try this out...

Unfortunately, you cannot just replace one command with another as the
error is indicating: each gives you different objects.

Now, you're not actually trying to proxy any monitoring through a remote
agent (as I believe this is intended to be implemented), so I'm not sure
your logic is going to work.

I wish I could be more help. I'll still try to do a bit of research if
I can find the time.

Marco

--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

Sakkieg

unread,
Oct 29, 2008, 1:23:00 AM10/29/08
to
When you discover and add network devices via the Opsmgr GUI you have the
option to select the RMS or any other MS as the proxy agent, I would think
that there is a way of doing this via Powershell as well and this is what I'm
looking for. This is all I need this script to do, once the device is added
to OpsMgr I have a set of monitors that probe the devices for certain
conditions and perform recoveries based on the value of these conditions.

Marco Shaw [MVP]

unread,
Oct 29, 2008, 7:56:27 AM10/29/08
to
Sakkieg wrote:
> When you discover and add network devices via the Opsmgr GUI you have the
> option to select the RMS or any other MS as the proxy agent, I would think
> that there is a way of doing this via Powershell as well and this is what I'm
> looking for. This is all I need this script to do, once the device is added
> to OpsMgr I have a set of monitors that probe the devices for certain
> conditions and perform recoveries based on the value of these conditions.

Thanks for clarifying. I'll take another peak at it. You might not be
able to use the Command Shell cmdlet for this, but maybe the SDK can be
called directly instead.

Marco Shaw [MVP]

unread,
Nov 4, 2008, 8:18:34 AM11/4/08
to

> Thanks for clarifying. I'll take another peak at it. You might not be
> able to use the Command Shell cmdlet for this, but maybe the SDK can be
> called directly instead.

I haven't given up yet. I haven't found an answer, but have asked a few
people for help. It just happens most are away likely all this week...

Marco

--
*Microsoft MVP - Admin Frameworks

Marco Shaw [MVP]

unread,
Nov 12, 2008, 8:44:10 AM11/12/08
to

> $Proxy = get-managementServer | where-object {$_.Name -eq
> "machine.domain.co.za"}
> #Write-Host $proxy.name
> add-remotelymanageddevice -proxyagent $Proxy -device
> $discovery_results.custommonitoringobjects

I don't have a large enough environment and am short on time to try to test.

Looks like this might be very easy:
PS>$rms=get-rootmanagementserver
PS>$rms.InsertRemotelyManagedDevices($discresults)

Let me know if you can try it out...

This may not be considered to be a "best practice" though.

Sakkieg

unread,
Nov 25, 2008, 4:24:02 AM11/25/08
to
Hi Marco,

I've been offline for a while, sorry for only getting back to you now.

I've tried, but to no avail, the error I get now is

======Start======

Exception calling "InsertRemotelyManagedDevices" with "1" argument(s):
"Specified argument was out of the range of valid values.
Parameter name: devicesToInsert"Cannot convert argument "0", with value:
"Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult", for
"InsertRemotelyManagedDevices" to type
"System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]":
"Cannot convert
"Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult" to
"System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]"."

=======End======

Just for your reference here is the script as it stands now

======Start Script=======

$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'

$dc = New-DeviceDiscoveryConfiguration -monitoringclass $networkdeviceclass
-fromipaddress '10.11.114.210' -toipaddress '10.11.114.210'
$encoding = new-object System.Text.UnicodeEncoding
$encodedCommunityString = $encoding.GetBytes("Public")
$dc.ReadOnlyCommunity =
[System.Convert]::ToBase64String($encodedCommunityString)
$managementServer = get-managementServer | where {$_.role -eq $root}
$discovery_results = start-discovery -ManagementServer: $managementServer
-DeviceDiscoveryConfiguration: $dc
$discovery_results | select-object -expand custommonitoringobjects
$rms=get-rootmanagementserver
$rms.InsertRemotelyManagedDevices($discovery_results)

======End Of Script======

Thank you so much for your efforst here

Sakkie

Marco Shaw [MVP]

unread,
Nov 25, 2008, 1:12:49 PM11/25/08
to

> Exception calling "InsertRemotelyManagedDevices" with "1" argument(s):
> "Specified argument was out of the range of valid values.
> Parameter name: devicesToInsert"Cannot convert argument "0", with value:
> "Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult", for
> "InsertRemotelyManagedDevices" to type
> "System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]":
> "Cannot convert
> "Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult" to
> "System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]"."

A generic list... Argh! ;-)

OK, I'm going to try to find a spot to actually test this... It may
take me a while...

Marco

--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw

*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition (due December
15th, 2008)

Sakkieg

unread,
Nov 25, 2008, 11:43:01 PM11/25/08
to
Thanks Marco

robertjue

unread,
Nov 13, 2009, 2:00:33 PM11/13/09
to
Guys, not sure if you figured it out... but if you take your script and replace the end with:

$rms.InsertRemotelyManagedDevices($DiscResults.custommonitoringobjects)

it will import the device - cheers

Sakkie wrote:

Re: Discover & Add Network Devices via PS
25-Nov-08

Thanks Marco

"Marco Shaw [MVP]" wrote:

Previous Posts In This Thread:

On Tuesday, October 28, 2008 6:30 AM
Sakkie wrote:

Discover & Add Network Devices via PS


II am trying to discover and add network devices via powershell on a
schedule. I use the following script;

$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'

$DDC = New-DeviceDiscoveryConfiguration -monitoringclass $networkdeviceclass
-fromipaddress 10.10.10.10 -toipaddress 10.10.10.10
$encoding = new-object System.Text.UnicodeEncoding


$encodedCommunityString = $encoding.GetBytes("public")
$DDC.ReadOnlyCommunity =
[System.Convert]::ToBase64String($encodedCommunityString)
$ManagementServer = get-managementServer | where {$_.IsRootManagementServer
-eq $True}

$DiscResults = start-discovery -ManagementServer: $ManagementServer
-DeviceDiscoveryConfiguration: $DDC
$DiscResults | select-object -expand custommonitoringobjects

$Proxy = get-managementServer | where-object {$_.Name -eq
"machine.domain.co.za"}

add-remotelymanageddevice -proxyagent $Proxy -device
$discovery_results.custommonitoringobjects

I'm having trouble with the last line;

add-remotelymanageddevice -proxyagent $Proxy -device
$discovery_results.custommonitoringobjects

Cannot bind parameter 'ProxyAgent'. Cannot convert
"Microsoft.EnterpriseManagement.Administration.ManagementServer" to
"Microsoft.EnterpriseManagement.Administration.AgentManagedComputer".

The orginal script read;
$agent = get-agent | where-object {$_.Name -eq "THUNDER.odyssey.com"}

I replaced that with;


$Proxy = get-managementServer | where-object {$_.Name -eq
"machine.domain.co.za"}

I need the RMS to be the proxy agent for these network devices.

This script was sources from SCOM Unleashed.

Any help would be appreciated.

On Tuesday, October 28, 2008 8:22 AM
Marco Shaw [MVP] wrote:

I don't have access to a large enough environment to try this out...
I don't have access to a large enough environment to try this out...

Unfortunately, you cannot just replace one command with another as the
error is indicating: each gives you different objects.

Now, you're not actually trying to proxy any monitoring through a remote
agent (as I believe this is intended to be implemented), so I'm not sure
your logic is going to work.

I wish I could be more help. I'll still try to do a bit of research if
I can find the time.

Marco

--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw


*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

On Wednesday, October 29, 2008 1:23 AM
Sakkie wrote:

When you discover and add network devices via the Opsmgr GUI you have the
When you discover and add network devices via the Opsmgr GUI you have the
option to select the RMS or any other MS as the proxy agent, I would think
that there is a way of doing this via Powershell as well and this is what I'm
looking for. This is all I need this script to do, once the device is added
to OpsMgr I have a set of monitors that probe the devices for certain
conditions and perform recoveries based on the value of these conditions.

"Marco Shaw [MVP]" wrote:

On Wednesday, October 29, 2008 7:56 AM
Marco Shaw [MVP] wrote:

Re: Discover & Add Network Devices via PS
Sakkieg wrote:

Thanks for clarifying. I'll take another peak at it. You might not be
able to use the Command Shell cmdlet for this, but maybe the SDK can be
called directly instead.

Marco

--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw


*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

On Tuesday, November 04, 2008 8:18 AM
Marco Shaw [MVP] wrote:

I haven't given up yet.
I haven't given up yet. I haven't found an answer, but have asked a few
people for help. It just happens most are away likely all this week...

Marco

--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw

*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

On Wednesday, November 12, 2008 8:44 AM
Marco Shaw [MVP] wrote:

I don't have a large enough environment and am short on time to try to test.
I don't have a large enough environment and am short on time to try to test.

Looks like this might be very easy:
PS>$rms=get-rootmanagementserver
PS>$rms.InsertRemotelyManagedDevices($discresults)

Let me know if you can try it out...

This may not be considered to be a "best practice" though.

Marco

--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw

*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

On Tuesday, November 25, 2008 4:24 AM
Sakkie wrote:

Hi Marco,I've been offline for a while, sorry for only getting back to you now.
Hi Marco,

I've been offline for a while, sorry for only getting back to you now.

I've tried, but to no avail, the error I get now is

======Start======

Exception calling "InsertRemotelyManagedDevices" with "1" argument(s):

"Specified argument was out of the range of valid values.
Parameter name: devicesToInsert"Cannot convert argument "0", with value:
"Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult", for
"InsertRemotelyManagedDevices" to type
"System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]":
"Cannot convert
"Microsoft.EnterpriseManagement.Administration.DiscoveryTaskResult" to
"System.Collections.Generic.IList`1[Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject]"."

=======End======

Just for your reference here is the script as it stands now

======Start Script=======

$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'
$dc = New-DeviceDiscoveryConfiguration -monitoringclass $networkdeviceclass
-fromipaddress '10.11.114.210' -toipaddress '10.11.114.210'
$encoding = new-object System.Text.UnicodeEncoding
$encodedCommunityString = $encoding.GetBytes("Public")
$dc.ReadOnlyCommunity =
[System.Convert]::ToBase64String($encodedCommunityString)
$managementServer = get-managementServer | where {$_.role -eq $root}
$discovery_results = start-discovery -ManagementServer: $managementServer
-DeviceDiscoveryConfiguration: $dc
$discovery_results | select-object -expand custommonitoringobjects
$rms=get-rootmanagementserver
$rms.InsertRemotelyManagedDevices($discovery_results)

======End Of Script======

Thank you so much for your efforst here

Sakkie

"Marco Shaw [MVP]" wrote:

On Tuesday, November 25, 2008 1:12 PM
Marco Shaw [MVP] wrote:

A generic list... Argh!


A generic list... Argh! ;-)

OK, I'm going to try to find a spot to actually test this... It may
take me a while...

Marco

--
*Microsoft MVP - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition (due December
15th, 2008)
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

On Tuesday, November 25, 2008 11:43 PM
Sakkie wrote:

Re: Discover & Add Network Devices via PS
Thanks Marco

"Marco Shaw [MVP]" wrote:

EggHeadCafe - Software Developer Portal of Choice
A Down and Dirty FileSystem Object Page Counter
http://www.eggheadcafe.com/tutorials/aspnet/5b5bfeb7-6c32-47ee-bd79-31f14d3f609c/a-down-and-dirty-filesyst.aspx

0 new messages