【问题标题】:SCOM Powershell How to Access IPAddress, Network and DefaultIPGatewaySCOM Powershell如何访问IP地址、网络和默认IP网关
【发布时间】:2019-11-18 15:37:46
【问题描述】:

我在 Powershell 脚本中查询 SCOM 以获取网络适配器的默认网关。使用以下命令我可以得到相关的监控对象:

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

好的,这个对象的属性是......

$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

需要注意的是,这里有这个特定对象类的属性以及来自父类的属性,以及它们的值。我的查询查找 Microsoft.Windows.NetworkAdapter 类的对象,但它返回的是 Microsoft.EnterpriseManagement.Monitoring.MonitoringObject 类型的实例。

我的问题是我想要DefaultIPGateway 值(以及IPAddressIPSubnet),它们是我最初搜索的原始Microsoft.Windows.NetworkAdapter 对象的属性。但是,如何实际获取该值(没有将该输出提取到文本数组并对其进行解析)让我感到困惑。

在网上搜索时,我发现一篇文章解释说,要在父类中定义这样的值,就是要重铸为该类型,如下所示:

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

我确信有一种方法可以获得这个值,但对于我的一生来说,我被困住了。除了告诉我相关的类和属性之外,我似乎无法让返回对象的任何方法做任何事情,除了获取实际值(呃!)之外的所有内容,这些值在上面的输出中都清晰可见。我显然不理解这里与派生类相关的一些东西,需要一点帮助。

有什么想法吗?

JJ

【问题讨论】:

    标签: powershell scom


    【解决方案1】:

    想通了(ty Michiel Wouter)

    $nic = Get-SCOMClass -name 'Microsoft.Windows.NetworkAdapter' | ` 获取-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

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

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 2019-02-03
      • 2017-02-13
      • 2016-01-29
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      相关资源
      最近更新 更多