manu ks
manu ks

Reputation: 63

Powershell : How to format the output of get-netadapter command to a single list/line with a delimiter

I'm trying to get the output of get-netadapter from powershell, from specific fields in the form of list/dict/json.

PS C:\Users\Administrator> Get-NetAdapter -IncludeHidden | Format-List -Property Name,AdminStatus,DriverFileName


Name           : Ethernet0
AdminStatus    : Up
DriverFileName : e1i63x64.sys

Name           : Ethernet (Kernel Debugger)
AdminStatus    : Down
DriverFileName : kdnic.sys

Name           : Teredo Tunneling Pseudo-Interface
AdminStatus    : Down
DriverFileName :

Name           : Microsoft IP-HTTPS Platform Interface
AdminStatus    : Down
DriverFileName :

Name           : 6to4 Adapter
AdminStatus    : Down
DriverFileName :

Required output format in the form of a list/dict/json.

Example format :

(Name: Ethernet0, AdminStatus: Up, DriverFileName : e1i63x64.sys;
 Name: Ethernet (Kernel Debugger), AdminStatus: Down, DriverFileName: kdnic.sys)

So the individual adapters are separated by ';' and the individual objects of a single adapter is separated by ','.

I tried using 'join' operator but that doesn't seem to work. ConvertTo-Json doesn't seem work if I use format-list/format-table

Upvotes: 2

Views: 1196

Answers (1)

Frenchy
Frenchy

Reputation: 17037

If you want to convert to json, directly do the command:

Get-NetAdapter -IncludeHidden | 
    Select-Object -Property Name,AdminStatus,DriverFileName |
    ConvertTo-Json 

result:

[
    {
        "Name":  "Connexion au réseau local* 7",
        "AdminStatus":  1,
        "DriverFileName":  "ndiswan.sys"
    },
    {
        "Name":  "Teredo Tunneling Pseudo-Interface",
        "AdminStatus":  2,
        "DriverFileName":  null
    },
    {
        "Name":  "Ethernet0",
        "AdminStatus":  1,
        "DriverFileName":  "e1i65x64.sys"
    },
    {
        "Name":  "Connexion au réseau local* 3",
        "AdminStatus":  1,
        "DriverFileName":  "rasl2tp.sys"
    },
    {
        "Name":  "6to4 Adapter",
        "AdminStatus":  2,
        "DriverFileName":  null
    }
]

Upvotes: 1

Related Questions