Approach 1
$ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1} $serverIP = $ip.ipaddress[0]
Approach 2
$computername = $env:COMPUTERNAME #Test-Connection $computername -count 1 | select Address,Ipv4Address Test-Connection $computername -count 1 | select @{Name="Computer Name";Expression={$_.Address}},@{Name="IPv4 Address";Expression={$_.Ipv4Address}}
Approach 3 – More Details
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "root\CIMV2" | where{$_.IPEnabled -eq "True"} clear Write-Host "# --------------------------------------" Write-Host "# Local IP address information" Write-Host "# --------------------------------------" foreach($objItem in $colItems) { Write-Host "Adapter:" $objItem.Description Write-Host " DNS Domain:" $objItem.DNSDomain Write-Host " Hostname:" $objItem.PSComputerName Write-Host " IPv4 Address:" $objItem.IPAddress[0] Write-Host " IPv6 Address:" $objItem.IPAddress[1] Write-Host " " }
Last Updated on March 10, 2016