Capture multiline, multi-group to Powershell variables

前端 未结 4 1627
忘了有多久
忘了有多久 2021-01-20 07:27

Ideally, I would like to create an object from ipconfig that allows us to drilldown to each adapter\'s attributes like this: $ip.$lan.$mac for the lan adapter\'s mac address

4条回答
  •  悲&欢浪女
    2021-01-20 08:03

    Another approach, if you want (1) an object and (2) something that should work in older versions of PowerShell, is to pull the network information using WMI:

    $adapters = Get-WmiObject -Class Win32_NetworkAdapterConfiguration
    
    $adapters | Format-Table Description,IPAddress,MACAddress
    
    $enabled = $adapters | Where-Object{$_.IPEnabled -eq $true}
    

    You can use the following to explore the full set of data that you get per adapter:

    $enabled | Format-List *
    

提交回复
热议问题