2

I am running a following script

[System.Net.Dns]::GetHostEntry('') | Where-Object {$_.AddressList -like "IPv4*"}

Which gives me this output:

HostName                      Aliases AddressList                                
--------                      ------- -----------                                
SERVER1.domain.com {}      {REDACTED_IPv6, IPv4.x.x.x}

My desired result would be this:

HostName                      Aliases AddressList                                
--------                      ------- -----------                                
SERVER1.domain.com                    {IPv4.x.x.x}

How can I go about achieving that?

1 Answer 1

3

Since the addresslist is an object itself you need to extract out the info you want. This should achieve your desired result.

[System.Net.Dns]::GetHostEntry('') |
    Select-Object HostName,
                  Aliases,
                  @{n="AddressList";e={$_.addresslist.ipaddresstostring}}

or

[System.Net.Dns]::GetHostEntry('') |
       Select-Object HostName,
                     Aliases,
                     @{n="AddressList";e={($_.addresslist|where addressfamily -eq InterNetwork).ipaddresstostring}}

or

[System.Net.Dns]::GetHostEntry('') |
       Select-Object HostName,
                     Aliases,
                     @{n="AddressList";e={$_.addresslist -like "10.*"}}

or

[System.Net.Dns]::GetHostEntry('') |
       Select-Object HostName,
                     Aliases,
                     @{n="AddressList";e={$_.addresslist -match "\d+\.\d+\."}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.