There are times when the name resolution of some URL does not happen. But when you check after sometime, it works perfect. So is there any way to track this intermittent name resolution issue. Yes there is!! This script helps you to monitor name resolution of a URL for the specified time. It will track the error and time in a CSV file. You can mention the duration (minutes, hours or days) for the script to monitor the name resolution.

NOTE: The powershell process running this script will hog memory over the time, hence you require to keep a track of available memory and processor periodically.

 

PowerShell
Edit|Remove
#Enter the URL to Monitor# 
$URL = "sales.contoso.com" 
 
#Enter the duration to monitor. Select only one" 
$Minutes = 1 
$Hours 
$Days 
 
 
 
If ($Minutes -ne $null) 
{ 
    $Stoptime=((Get-Date).AddMinutes($Minutes)).ToString("ddMMyyyhhmm") 
} 
 
elseif ($Hours -ne $null) 
{ 
    $Stoptime=((Get-Date).AddHours($Hours)).ToString("ddMMyyyhhmm") 
} 
 
elseif ($Days -ne $null) 
{ 
    $Stoptime=((Get-Date).Adddays($Days)).ToString("ddMMyyyhhmm") 
} 
 
$results = @() 
 
Do  
{ 
    try  
        { 
            if (Resolve-DnsName $URL -ErrorAction Stop) {Out-Null} 
        } 
    
    catch 
        { 
 
           $ErrorString = $Error[0].Exception | Out-String 
           $ErrorString = ($ErrorString).Replace("`r`n","") 
           $TimeOfError = (Get-Date).ToString() 
 
            
 
           $Details = @{ 
                        Error = $ErrorString 
                        Time = $TimeOfError 
                      } 
            $results +New-Object PSObject -Property $details 
            
            $results | Export-Csv D:\Monitoring.csv -Append -NoTypeInformation 
 
        } 
} 
 
until 
((Get-Date).ToString("ddMMyyyhhmm"-eq $Stoptime)