I am using Get-NetIPAddress. ALL I want is the actual address without ANY formatting or tables or anything.
If I use
(Get-NetIPAddress).IPAddres
I get a list of addresses for all ports. I want only a single port so I tried to pipe it but gave nothing in return:
(Get-NetIPAddress).IPv4Address | Where-Object InterfaceAlias -eq "MyPortName"
But if I do this:
Get-NetIPAddress.IPv4Address | Where-Object InterfaceAlias -eq "MyPortName"
It says that this is an invalid command.
If I use this:
Get-NetIPAddress | Where-Object InterfaceAlias -eq "MyPortName" | Where-Object AddressFamily -eq IPv4 | Select-Object IPAddress
I get:
IPAddress
---------
10.45.22.100
So what is going on when I put parenthesis around Get-NetIPAddress and how can I get JUST the darn address number for a particular port?
By enclosing a command with ()
you create an order of precedence, so everything inside of ()
executes first and after that your other commands are evaluated.
also, there is no such construct as cmdlet.property
as for the second part, after you do (Get-NetIPAddress).IPv4Address
you are probably getting another object, just compare output from:
Get-NetIPAddress | Get-Member
and
(Get-NetIPAddress).IPv4Address | Get-Member
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With