Created
          October 24, 2015 12:27 
        
      - 
      
 - 
        
Save PrateekKumarSingh/586f2d3d43f7e8cb07ce to your computer and use it in GitHub Desktop.  
  
    
      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
    
  
  
    
  | 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 | |
| } | |
| } | 
#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
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thanks, very useful function! I slightly refactored it to look a bit more pretty! resolve-host.ps1
I'm subscribed to your blog, the stuff you are doing with Powershell is very exciting!