Windowsパソコンでネットワーク越しにパソコンのネットワーク情報を得たい時に役立つ機能の紹介です。職場のパソコンのインベントリ情報を遠隔で収集したいときなどに活用します。
WMIを使うので以下サイトを参考にして、接続できるようにしておく必要があります。
実施方法
PowerShellで以下のコマンドを実行すると、$address変数に取得した情報が格納されます。-FilterにIPEnabled=Trueを指定することで、有効なアダプタの情報だけを取得しています。
1 |
$address = Get-WmiObject Win32_NetworkAdapterConfiguration -computername ホスト名orIP -Filter "IPEnabled=True" |
Select-Objectで内容を確認してみると、次のような情報が取得されます。この中でIPAddressにIPアドレスや、MACAddressにMACアドレスが格納されているので参照します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
PS C:\> $address | Select-Object * PSComputerName : PC001 DHCPLeaseExpires : Index : 2 Description : Hyper-V Virtual Ethernet Adapter DHCPEnabled : False DHCPLeaseObtained : DHCPServer : DNSDomain : DNSDomainSuffixSearchOrder : {} DNSEnabledForWINSResolution : False DNSHostName : PC001 DNSServerSearchOrder : DomainDNSRegistrationEnabled : False FullDNSRegistrationEnabled : False IPAddress : {172.25.208.1, fe80::997c:76c6:7eeb:2421} IPConnectionMetric : 15 IPEnabled : True IPFilterSecurityEnabled : False WINSEnableLMHostsLookup : True WINSHostLookupFile : WINSPrimaryServer : WINSScopeID : WINSSecondaryServer : __GENUS : 2 __CLASS : Win32_NetworkAdapterConfiguration __SUPERCLASS : CIM_Setting __DYNASTY : CIM_Setting __RELPATH : Win32_NetworkAdapterConfiguration.Index=2 __PROPERTY_COUNT : 61 __DERIVATION : {CIM_Setting} __SERVER : PC001 __NAMESPACE : root\cimv2 __PATH : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration.Index=2 ArpAlwaysSourceRoute : ArpUseEtherSNAP : Caption : [00000002] Hyper-V Virtual Ethernet Adapter DatabasePath : %SystemRoot%\System32\drivers\etc DeadGWDetectEnabled : DefaultIPGateway : DefaultTOS : DefaultTTL : ForwardBufferMemory : GatewayCostMetric : IGMPLevel : InterfaceIndex : 42 IPPortSecurityEnabled : IPSecPermitIPProtocols : {} IPSecPermitTCPPorts : {} IPSecPermitUDPPorts : {} IPSubnet : {255.255.240.0, 64} IPUseZeroBroadcast : IPXAddress : IPXEnabled : IPXFrameType : IPXMediaType : IPXNetworkNumber : IPXVirtualNetNumber : KeepAliveInterval : KeepAliveTime : MACAddress : 00:15:3F:C6:7B:21 MTU : NumForwardPackets : PMTUBHDetectEnabled : PMTUDiscoveryEnabled : ServiceName : VMSNPXYMP SettingID : {F508AF82-3E35-4E5D-A100-65540B8C574E} TcpipNetbiosOptions : 0 TcpMaxConnectRetransmissions : TcpMaxDataRetransmissions : TcpNumConnections : TcpUseRFC1122UrgentPointer : TcpWindowSize : Scope : System.Management.ManagementScope Path : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration.Index=2 Options : System.Management.ObjectGetOptions ClassPath : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration Properties : {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, DatabasePath...} SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...} Qualifiers : {dynamic, Locale, provider, UUID} Site : Container : PSComputerName : PC001 DHCPLeaseExpires : 20230720224527.000000+540 Index : 3 Description : Marvell AVASTAR Wireless-AC Network Controller DHCPEnabled : True DHCPLeaseObtained : 20230720184527.000000+540 DHCPServer : 10.109.4.1 DNSDomain : DNSDomainSuffixSearchOrder : {} DNSEnabledForWINSResolution : False DNSHostName : PC001 DNSServerSearchOrder : {221.113.139.148, 202.234.233.212} DomainDNSRegistrationEnabled : False FullDNSRegistrationEnabled : True IPAddress : {10.109.4.119, fe80::2dc4:dad8:9b65:db5a} IPConnectionMetric : 55 IPEnabled : True IPFilterSecurityEnabled : False WINSEnableLMHostsLookup : True WINSHostLookupFile : WINSPrimaryServer : WINSScopeID : WINSSecondaryServer : __GENUS : 2 __CLASS : Win32_NetworkAdapterConfiguration __SUPERCLASS : CIM_Setting __DYNASTY : CIM_Setting __RELPATH : Win32_NetworkAdapterConfiguration.Index=3 __PROPERTY_COUNT : 61 __DERIVATION : {CIM_Setting} __SERVER : PC001 __NAMESPACE : root\cimv2 __PATH : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration.Index=3 ArpAlwaysSourceRoute : ArpUseEtherSNAP : Caption : [00000003] Marvell AVASTAR Wireless-AC Network Controller DatabasePath : %SystemRoot%\System32\drivers\etc DeadGWDetectEnabled : DefaultIPGateway : {10.109.4.1} DefaultTOS : DefaultTTL : ForwardBufferMemory : GatewayCostMetric : {0} IGMPLevel : InterfaceIndex : 28 IPPortSecurityEnabled : IPSecPermitIPProtocols : {} IPSecPermitTCPPorts : {} IPSecPermitUDPPorts : {} IPSubnet : {255.255.252.0, 64} IPUseZeroBroadcast : IPXAddress : IPXEnabled : IPXFrameType : IPXMediaType : IPXNetworkNumber : IPXVirtualNetNumber : KeepAliveInterval : KeepAliveTime : MACAddress : C4:9D:ED:B2:94:D2 MTU : NumForwardPackets : PMTUBHDetectEnabled : PMTUDiscoveryEnabled : ServiceName : mrvlpcie8897 SettingID : {AA36E3DF-D257-4CB0-ABA2-F8676EBE7050} TcpipNetbiosOptions : 0 TcpMaxConnectRetransmissions : TcpMaxDataRetransmissions : TcpNumConnections : TcpUseRFC1122UrgentPointer : TcpWindowSize : Scope : System.Management.ManagementScope Path : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration.Index=3 Options : System.Management.ObjectGetOptions ClassPath : \\PC001\root\cimv2:Win32_NetworkAdapterConfiguration Properties : {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, DatabasePath...} SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...} Qualifiers : {dynamic, Locale, provider, UUID} Site : Container : |
大抵複数のアダプタがあるので、添え字を指定してこんな感じで参照します。
1 2 |
PS C:\> Write-Host $address[0].IPAddress 172.25.208.1 fe80::997c:76c6:7eeb:2421 |