#author("2020-04-04T18:27:13+09:00","","")
#author("2021-02-10T22:39:17+09:00","","")
#navi(..//)

* ネットワークアダプター一覧を取得する [#o8b348bb]
PowerShellを使ってネットワークアダプタの一覧を取得するには、''Get-NetAdapter'' コマンドレットを使うと~
PC上のネットワークアダプタ一覧が表示されます。~
以下に Get-NetAdapter コマンドレットの使用例をいくつか記します。

#htmlinsert(win-top.html)
#contents

* 動作確認環境 [#g61d1a36]
- Windows 10 ver.1903
- PowerShell 
 PS C:\> $PSVersionTable.PSVersion.ToString()
 5.1.18362.628

* 関連記事 [#y5407a6a]
-[[PowerShellでネットワークアダプタの情報を取得する・Get-NetAdapter,Get-NetIPConfiguration>PowerShell/ネットワークアダプタの情報を取得する Get-NetAdapter,Get-NetIPConfiguration]]

* 関連サイト [#u5108ba9]
-[[Microsoft | Docs Get-NetAdapter>https://docs.microsoft.com/en-us/powershell/module/netadapter/get-netadapter]]

* Get-NetAdapter コマンドレットを実行してみる [#ebfa1991]
Get-NetAdapter コマンドレットを引数なしで実行した時の出力です。
PS C:\> Get-NetAdapter

 Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
 ----                      --------------------                    ------- ------       ----------             ---------
 Wi-Fi                     Intel(R) Dual Band Wireless-AC 7265          10 Up           xx-xx-xx-xx-xx-xx     866.7 Mbps
 イーサネット              Intel(R) Ethernet Connection (3) I21...       7 Disconnected xx-xx-xx-xx-xx-xx          0 bps
 Bluetooth ネットワーク... Bluetooth Device (Personal Area Netw...       4 Disconnected xx-xx-xx-xx-xx-xx         3 Mbps
 イーサネット 2            VirtualBox Host-Only Ethernet Adapter         2 Up           xx-xx-xx-xx-xx-xx         1 Gbps

コントロールパネルのネットワーク接続を確認すると、同じ内容が出力されているのが確認できます。
#ref(01.png)
#br

* Where-Object コマンドレットを使って有効なアダプタ一覧を取得する [#l39bf494]
Where-Objectコマンドレットを使ってStatusがUpになっているアダプタのみ表示させています。
 PS C:\> Get-NetAdapter | Where-Object {$_.Status -eq "Up"}
 
 Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
 ----                      --------------------                    ------- ------       ----------             ---------
 Wi-Fi                     Intel(R) Dual Band Wireless-AC 7265          10 Up           xx-xx-xx-xx-xx-xx     866.7 Mbps
 イーサネット 2            VirtualBox Host-Only Ethernet Adapter         2 Up           xx-xx-xx-xx-xx-xx         1 Gbps

* Get-NetAdapter コマンドレットの各種プロパティなど [#e5464815]
以下のコマンドで Get-NetAdapter コマンドレットが持つメソッドやプロパティ一覧を確認することができます。~
たくさんのメソッド、プロパティがあるので、以下の実行例では省略しています。
 PS C:\> Get-NetAdapter | Get-Member
 
    TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/StandardCimv2/MSFT_NetAdapter
 
 Name                                             MemberType     Definition
 ----                                             ----------     ----------
 DriverVersion                                    AliasProperty  DriverVersion = DriverVersionString
 ifAlias                                          AliasProperty  ifAlias = Name
 ifDesc                                           AliasProperty  ifDesc = InterfaceDescription
 ifIndex                                          AliasProperty  ifIndex = InterfaceIndex
 <省略> 
 DriverName                                       Property       string DriverName {get;}
 DriverProvider                                   Property       string DriverProvider {get;}
 DriverVersionString                              Property       string DriverVersionString {get;}
 <省略> 
 MacAddress                                       ScriptProperty System.Object MacAddress {get=$out = ""...
 MediaConnectionState                             ScriptProperty System.Object MediaConnectionState {get=[Microsoft.P...
 MediaType                                        ScriptProperty System.Object MediaType {get=$out = switch ($this.Nd...
 NdisVersion                                      ScriptProperty System.Object NdisVersion {get=$out = if ($this.Driv...
 PhysicalMediaType                                ScriptProperty System.Object PhysicalMediaType {get=$out = switch (...
 Status                                           ScriptProperty System.Object Status {get=$NetAdapter = $this;... 

** アダプタのドライバ名を取得する [#p4bd370d]
上記で Get-Member を使ってメソッド、プロパティ一覧を取得しました。~
Name, ifDesc, DriverNameを表示してみます。
 PS C:\> Get-NetAdapter | Select-Object Name,ifDesc, DriverName
 
 Name                       ifDesc                                   DriverName
 ----                       ------                                   ----------
 Wi-Fi                      Intel(R) Dual Band Wireless-AC 7265      \SystemRoot\System32\drivers\Netwtw04.sys
 イーサネット               Intel(R) Ethernet Connection (3) I218-LM \SystemRoot\System32\drivers\e1i65x64.sys
 Bluetooth ネットワーク接続 Bluetooth Device (Personal Area Network) \SystemRoot\System32\drivers\bthpan.sys
 イーサネット 2             VirtualBox Host-Only Ethernet Adapter    \SystemRoot\system32\DRIVERS\VBoxNetAdp6.sys

以上、Get-NetAdapter コマンドレットを使ってアダプタ一覧およびアダプタ情報を取得する方法でした。

#htmlinsert(win-btm.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS