Get all IPV4 address with power shell

Hello

I need to be able to output all IPV4 address to one line in txt file. Here is what I am using currently:

$IP = (get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.Ipaddress.length -gt 1 }).ipaddress[0]

 

When I run this command on a computer that has wired network adapter it works fine. When I run this same command against a computer that has wireless adaptor I get nothing in the output file. Can you tell me what I am doing wrong or point to a web resource please.

Thanks



February 12th, 2015 8:33pm

Hi,

Try it this way:

Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled=True" |
    Select -ExpandProperty IPAddress |
        Out-File .\ipAddrList.txt
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 8:40pm

Which will output both IPv4 and IPv6.  To filter just detect the colon in the string.

Where{ $_ -notmatch ':'}

February 12th, 2015 8:56pm

Which will output both IPv4 and IPv6.  To filter just detect the colon in the string.

Where{ $_ -notmatch ':'}

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 9:18pm

that got me what I want now the next question if I wanted to put it on in one line for example

192.168.0.1,192.168.0.2,192.168.3.1

Do I need to string to do this?

February 13th, 2015 2:53am

Hi,

You can use -join:

$ipList = @(
    '10.0.0.1'
    '10.0.0.2'
    '10.0.0.3'
)

$ipListJoined = $ipList -join ','

$ipList
$ipListJoined

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 2:57am

I was able to get it work by adding -join ',';  thanks so much
February 13th, 2015 3:26am

Cheers, you're very welcome. Glad it worked out.
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 3:33am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics