Ok, there are tons of ways to get IP addresses via Powershell:
What I have is a web server that has several IP's assigned to it as it runs multiple sites. I want to get the actual IP address of the server itself.
There are a ton of ways to get the IP addresses, but the one I found useful is:
(gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }).ipaddress
It lists the IP addresses in a list and is nice an neat with no need to really mess with it.
Now, let's say I have a list of IP's like this:
10.224.97.40
10.224.97.39
10.224.96.36
10.224.96.34
10.224.96.32
10.224.96.30
And the actual IP address of the server is:
10.224.96.36
How can I just get that one IP returned KNOWING it is the server IP and not a site IP?
If I use another method:
[System.Net.Dns]::GetHostAddresses($env:COMPUTERNAME)
I get data like:
Address : 509665290
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
IPAddressToString : 10.224.96.30
Address : 543219722
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
IPAddressToString : 10.224.96.32
...and so on
There is no real way to tell which is the adapter address...
Using:
gwmi -query "Select IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True"
is worthless as it returns the IP addresses in an array:
__GENUS : 2
__CLASS : Win32_NetworkAdapterConfiguration
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
IPAddress : {10.224.97.40, 10.224.97.39, 10.224.96.36, 10.224.96.34...}
PSComputerName :
Any ideas?
Thanks!