1

I am querying SCOM in a Powershell script to need get the default gateway for a network adapter. Using the following command I am able to get the related monitoring object:

$nic = Get-SCOMClass -name 'Microsoft.Windows.NetworkAdapter' | Get-SCOMClassInstance | `
Where-Object { $_.Path -eq 'vscomwin01d.XXXX.YYY.com' } 

Okay, the properties for this object are....

$nic | fl

[Microsoft.Windows.Server.10.0.NetworkAdapter].SlotNumber : 192
[Microsoft.Windows.Server.NetworkAdapter].AdapterType     : Unknown
[Microsoft.Windows.Server.NetworkAdapter].Index           : 3
[Microsoft.Windows.Server.NetworkAdapter].Manufacturer    : VMware, Inc.
[Microsoft.Windows.Server.NetworkAdapter].MACAddress      : 00-50-56-9B-12-48
[Microsoft.Windows.Server.NetworkAdapter].ServiceName     : vmxnet3
[Microsoft.Windows.Server.NetworkAdapter].PerfmonInstance : vmxnet3 Ethernet Adapter
[Microsoft.Windows.Server.NetworkAdapter].DHCPEnabled     : false
[Microsoft.Windows.Server.NetworkAdapter].DHCPServer      : 255.255.255.255
[Microsoft.Windows.Server.NetworkAdapter].DNSDomain       : XXXX.YYY.com
[Microsoft.Windows.Server.NetworkAdapter].IPAddress       : 10.78.152.67,fe80::49cf:8804:bfb3:8645%3
[Microsoft.Windows.Server.NetworkAdapter].IPSubnet        : 255.255.255.0
[Microsoft.Windows.NetworkAdapter].Bandwidth              : (null)
[Microsoft.Windows.NetworkAdapter].MaxSpeed               : (null)
[Microsoft.Windows.NetworkAdapter].ProductName            : vmxnet3 Ethernet Adapter
[Microsoft.Windows.NetworkAdapter].DefaultIPGateway       : 10.78.152.1
[Microsoft.Windows.NetworkAdapter].DHCPHostname           : (null)
[Microsoft.Windows.NetworkAdapter].IPEnabled              : True
[Microsoft.Windows.LogicalDevice].DeviceID                : {C5E43C2B-221E-46E0-8E15-30CDF9480155}
[Microsoft.Windows.LogicalDevice].Name                    : Ethernet0
[Microsoft.Windows.LogicalDevice].Description             :
[System.ConfigItem].ObjectStatus                          : System.ConfigItem.ObjectStatusEnum.Active
[System.ConfigItem].AssetStatus                           : (null)
[System.ConfigItem].Notes                                 : (null)
[System.Entity].DisplayName                               : Ethernet0
[Microsoft.Windows.Computer].PrincipalName                : vscomwin01d.XXXX.YYY.com
IsManaged                                                 : True
HealthState                                               : Success
StateLastModified                                         : 11/15/2019 8:11:27 PM
IsAvailable                                               : True
AvailabilityLastModified                                  : 11/14/2019 2:54:59 PM
InMaintenanceMode                                         : False
MaintenanceModeLastModified                               :
MonitoringClassIds                                        : {97116693-b8e7-f4b3-fdd6-9644eb842a4d}
LeastDerivedNonAbstractMonitoringClassId                  : 97116693-b8e7-f4b3-fdd6-9644eb842a4d
ManagementGroup                                           : XX-DEV
Name                                                      : {C5E43C2B-221E-46E0-8E15-30CDF9480155}
Path                                                      : vscomwin01d.XXXX.YYY.com
DisplayName                                               : Ethernet0
FullName                                                  : Microsoft.Windows.Server.10.0.NetworkAdapter:vscomwin01d.XXXX.YYY.com;{C5E43C2B-221E-46E0-8E15-30CDF9480155}
ManagementPackClassIds                                    : {97116693-b8e7-f4b3-fdd6-9644eb842a4d}
LeastDerivedNonAbstractManagementPackClassId              : 97116693-b8e7-f4b3-fdd6-9644eb842a4d
TimeAdded                                                 : 11/15/2019 8:10:09 PM
LastModifiedBy                                            :
Values                                                    : {192, Unknown, 3, VMware, Inc....}
LastModified                                              : 11/15/2019 8:10:09 PM
IsNew                                                     : False
HasChanges                                                : False
Id                                                        : 8fbb5f95-2f11-2b72-0914-0f7eb1237b10
ManagementGroupId                                         : feb5e986-bd3d-e1f8-716c-214d041a0194
GroupsAsDifferentType                                     : False
ViewName                                                  : ManagedEntityGenericView
ObjectMode                                                : All

The thing to note is there are properties of this particular object class as well as properties from parent classes visible here, all along with their values. My query looks for an object of class Microsoft.Windows.NetworkAdapter, but instead it returns an instance of type Microsoft.EnterpriseManagement.Monitoring.MonitoringObject.

My problem is I want the DefaultIPGateway value (as well as IPAddress and IPSubnet), which are properties of the original Microsoft.Windows.NetworkAdapter object I was searching for in the first place. However, how to actually get this value (short of extracting that output to a text array and parsing it) is baffling me.

In searching online I found one article explaining that to get a value like this defined in a parent class was to recast as that type as shown below:

PS > ([Microsoft.Windows.NetworkAdapter]$nic).DefaultIPGateway
Unable to find type [Microsoft.Windows.NetworkAdapter].
At line:1 char:3
+ ([Microsoft.Windows.NetworkAdapter]$nic).DefaultIPGateway
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Windows.NetworkAdapter:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

I'm sure there's a way to get this value but for the life of me I'm stuck. I couldn't seem to make any of the methods of the returned objects to do anything but tell me about the related classes and properties, everything but get the actual values (ugh!) which are all clearly visible in the output above. I'm obviously not understanding something here related to derived classes and need a little help.

Any ideas?

JJ

HAL9256
  • 12,384
  • 1
  • 34
  • 46

1 Answers1

0

Figured it out (ty Michiel Wouter)

$nic = Get-SCOMClass -name 'Microsoft.Windows.NetworkAdapter' | ` Get-SCOMClassInstance | Where-Object { $_.Path -eq 'vscomwin01d.XXXX.YYY.com' }

$nic.'[Microsoft.Windows.Server.NetworkAdapter].IPAddress'.value 10.78.152.67,fe80::49cf:8804:bfb3:8645%3

$nic.'[Microsoft.Windows.Server.NetworkAdapter].IPSubnet'.value 255.255.255.0

$nic.'[Microsoft.Windows.NetworkAdapter].DefaultIPGateway'.value 10.78.152.1

Ref: http://blog.wouters.it/2017/07/scom-using-bracket-noteproperties-in.html