Skip to content

Instantly share code, notes, and snippets.

@h3nryza
Created July 17, 2018 17:27
Show Gist options
  • Save h3nryza/46266948ec56662076c5a71741e56caa to your computer and use it in GitHub Desktop.
Save h3nryza/46266948ec56662076c5a71741e56caa to your computer and use it in GitHub Desktop.
PowerShell get IP Information
#Get all Valid IPV4
Get-CimInstance Win32_NetworkAdapterConfiguration | where{$_.ipenabled -like "True"}| Select -ExpandProperty IPAddress | where{$_ -like "*.*.*"}
#Select first valid V4
Get-CimInstance Win32_NetworkAdapterConfiguration | where{$_.ipenabled -like "True"}| Select -ExpandProperty IPAddress | where{$_ -like "*.*.*"} | Select -first 1
#Quick method
$localIpAddress=((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
#Longer Method
$ipaddress=([System.Net.DNS]::GetHostAddresses('PasteMachineNameHere')|Where-Object {$_.AddressFamily -eq "InterNetwork"} | select-object IPAddressToString)[0].IPAddressToString
#Prone to DNS Failure
Test-Connection -ComputerName localhost -Count 1 | Select IPV4Addres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment