1

I'm a powershell newbie.

If I run Get-NetIPConfiguration -Detailed I can see the IPv4 DHCP status. This is a good start - took me a lot of googling to get this far:

PS C:\Windows\system32> Get-NetIPConfiguration -Detailed

ComputerName                          : VM-172-26-39-24
InterfaceAlias                        : Ethernet
InterfaceIndex                        : 6
InterfaceDescription                  : Red Hat VirtIO Ethernet Adapter
NetCompartment.CompartmentId          : 1
NetCompartment.CompartmentDescription : Default Compartment
NetAdapter.LinkLayerAddress           : FA-16-3E-FF-0D-60
NetAdapter.Status                     : Up
NetProfile.Name                       : Network
NetProfile.NetworkCategory            : Public
NetProfile.IPv6Connectivity           : NoTraffic
NetProfile.IPv4Connectivity           : Internet
IPv6LinkLocalAddress                  : fe80::x:x:x:x
IPv4Address                           : 172.26.39.249
IPv6DefaultGateway                    :
IPv4DefaultGateway                    : 172.26.36.1
NetIPv6Interface.NlMTU                : 9000
NetIPv4Interface.NlMTU                : 9000
NetIPv6Interface.DHCP                 : Enabled
NetIPv4Interface.DHCP                 : Disabled
DNSServer                             : x.x.x.x
                                        x.x.x.x

But if I run something like Get-NetIPConfiguration -Detailed | select InterfaceAlias,NetIPv4Interface.DHCP

I get an empty field?

PS C:\Windows\system32> Get-NetIPConfiguration -Detailed | `
select InterfaceAlias, NetIPv4Interface.DHCP

InterfaceAlias NetIPv4Interface.DHCP
-------------- ---------------------
Ethernet          

Am I doing something wrong?

If I remove the trailing .DHCP ("what's in there?") I see nothing recognisable

PS C:\Windows\system32> Get-NetIPConfiguration -Detailed | select InterfaceAlias, NetIPv4Interface

InterfaceAlias NetIPv4Interface
-------------- ----------------
Ethernet       MSFT_NetIPInterface (Name = "@55?55;", CreationClassName = "", SystemCreationClassName = "", SystemName = "")

1 Answer 1

2

You need to calculate the sub property when used in a Select statement:

Get-NetIPConfiguration -Detailed | `
select InterfaceAlias, @{N="DHCP";E={$_.NetIPv4Interface.DHCP}}

Or try this:

Get-NetIPConfiguration | Select -ExpandProperty NetIPv4Interface | Select InterfaceAlias,DHCP

...or you could just retrieve the config, put it in a variable then get the desired sub-properties:

$Config = Get-NetIPConfiguration

$Config | forEach {
    [pscustomobject]@{InterFaceAlias=$_.InterFaceAlias;DHCP=$_.NetIPv4Interface.DHCP}
}
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.