Created
July 17, 2018 17:27
-
-
Save h3nryza/46266948ec56662076c5a71741e56caa to your computer and use it in GitHub Desktop.
PowerShell get IP Information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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