1つの CLS 2 $ NetworkAdapters =は、Get-WmiObjectコマンド-ClassのWin32_NetworkAdapter | ?{ $ _ .PhysicalAdapter -eq ' 真の '} | NetConnectionID選択 3 のforeach($ NetworkAdapter で $ NetworkAdapters ) 4 { 5 $ CurrentAdapter =($ NetworkAdapter | .NetConnectionID NetConnectionIDを選択)は 6 $結果 = CMD / C netshインターフェイスのIPを表示する設定名= $ CurrentAdapter 7 $ IPInfos =($結果 |外の文字列)-split([環境] ::改行) 8 $ DisconnectStatus = $真 9 のforeach($ IPInfo で $ IPInfos ) 10 { 11 12 であれば($ IPInfo 様 '* IPアドレス* ') 13 { 14 $ DisconnectStatus = $偽 15 $ CurrentIPv4 = $ IPInfo 16 $ DeviceIP =($ CurrentIPv4 -replace ( 'IPアドレス:'、 ''))。(トリム) 17 #$ DeviceIP 18 書き込みホスト"デバイス:$ CurrentAdapter / IPアドレス:$ DeviceIP " - ForegroundColorブルー 19 } 20 } 21 であれば($ DisconnectStatus ) 22 { 23 書き込みホスト" デバイス:$ CurrentAdapter /ステータス:切断" - ForegroundColorブルー 24 } 25 }