Created
October 24, 2015 12:27
-
-
Save PrateekKumarSingh/586f2d3d43f7e8cb07ce to your computer and use it in GitHub Desktop.
This file contains 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
Function Resolve-Host() | |
{ | |
Param( | |
[Parameter(Mandatory=$true,Position=0)] $HostEntry, | |
[Switch] $HostnameToIP, | |
[Switch] $FlushDNS | |
) | |
If($FlushDNS) | |
{ | |
Ipconfig /FlushDNS | Out-Null | |
} | |
If($HostnameToIP) | |
{ | |
$object = @() | |
$HostEntry | %{ | |
$Object += New-Object psobject -Property @{ HostName= $_ | |
IPAddress=$([System.Net.Dns]::gethostentry($_).AddressList.IPAddressToString) | |
} | |
} | |
Return $object | select Hostname, IPAddress | |
} | |
else | |
{ | |
$object = @() | |
$HostEntry | %{ | |
$Object += New-Object psobject -Property @{ IPAddress= $_ | |
HostName=$([System.Net.Dns]::gethostentry($_).HostName) | |
} | |
} | |
Return $object | select IPAddress, Hostname | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Must First run
. .\Resolve-Host.Ps1
there is space after the first dot
#Then
Resolve-Host "1.1.1.1","8.8.8.8"
Resolve-Host "bing.com" -HostnameToIP
Resolve-Host (gc .\IPAddresses.txt) | FT -AutoSize
Resolve-Host (gc .\IPAddresses.txt) -HostnameToIP | FT -AutoSize