Skip to content

Instantly share code, notes, and snippets.

@ethack
Forked from PrateekKumarSingh/Resolve-Host.Ps1
Last active February 19, 2021 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethack/8fe44b9ccc7790e47eb738e86047b95a to your computer and use it in GitHub Desktop.
Save ethack/8fe44b9ccc7790e47eb738e86047b95a to your computer and use it in GitHub Desktop.
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