Showing posts with label DNS. Show all posts
Showing posts with label DNS. Show all posts

Monday 24 October 2016

PowerShell - To Perform DNS Resolution Check-Up

So this is my second PowerShell script created by me. The first one was so simple and I use it in my XenDesktop environment. This script on the other hand, is aprt of my initiative in performing Active Directory clean-up in my environment. 

The task of the script is simple - check the IP address of a machine name, then check the hostname of that IP address. 

- If the machine name (A host record) and the hostname (PTR record) is similar, we are good. 
- If the machine name (A host record) and the hostname (PTR record) is different, error prompted
- If the machine name (A host record) is available but the hostname (no PTR record) is not, error prompted
- If the machine is not avaiable (no A host record), error prompted.

I use $PSScriptRoot so the location of the script is dynamic, it does not necessarily need to be put at a specific location.

This is only part 1. I wish to add more features so it could be better next time.



############################################################
#
#       This script is created by Heiry Zulkifli, in order to check DNS resolutions for hostnames.
# www.datakraf.co.nz
#
#######################################################################

Function FunctChkIPAdd ($Machine)
{
Try
{
$arr = [System.Net.Dns]::GetHostAddresses($Machine)  | findstr "IPAddressToString"
$SplitArr = $arr -split ': '
$IPAdd = $SplitArr[1]
$ErrorCode = 0
RETURN $ErrorCode, $IPAdd
} Catch {
$ErrorCode = 1
RETURN $ErrorCode, $IPAdd
}
}
Function FunctChkHostname ($IPAdd)
{
Try
{
$arr = [System.Net.Dns]::GetHostbyAddress($IPAdd) | findstr "{}"
$SplitArr = $arr -split ' '
$FQDN = $SplitArr[0]
$SplitArr2 = $FQDN.Split('.')
$Hostname = $SplitArr2[0]
$ErrorCode = 0
RETURN $ErrorCode, $Hostname
} Catch {
$ErrorCode = 2
RETURN $ErrorCode, $Hostname
}
}
$strFileName = "$PSScriptRoot\result.txt"
if (Test-path $strFileName) {remove-item $strFileName}
"MACHINENAME IP ADDRESS HOSTNAME STATUS" >$strFileName
write-host ("Script starts...")
write-host ("Performing Flush DNS...")
ipconfig /flushdns
write-host ("Flush DNS completed")
write-host (".")
write-host (".")
write-host (".")

forEach ($Machine in get-Content $PSScriptRoot\machines.txt)
{
  write-host ("Checking $Machine")
$ResultIPAdd = FunctChkIPAdd ($Machine)
If ($ResultIPAdd[0] -eq 0)
{
$ResultHostName = FunctChkHostname ($ResultIPAdd[1])
$Result = $ResultHostName[0]
IF ($Result -eq 0)
{ $IPAdd = $ResultIPAdd[1]
$HostName = $ResultHostName[1]
IF ($Machine -eq $HostName)
{
$info = "$Machine $IPAdd $HostName | OK"
} ELSE {
$info = "$Machine $IPAdd $HostName---------------| ERROR - Maching Different With Hostname"
}
} ELSE {
$info = "$Machine $IPAdd -------------------------------------------| ERROR-HostName Not Found"
}
} ELSE {
$info = "$Machine ----------------------------------------------| ERROR-machine Name Not Found"
}
$info >> $strFileName
$hostname=""
write-host (".................................Completed")
}
write-host (".")
write-host (".")
write-host (".")
write-host ("Script completed. Please check result.txt")



When launches...




Example of result.txt


Share:

Wednesday 19 February 2014

Add a Member Server To Domain Failed Due to DNS Configuration

This would be my first post regarding Server 2012 (pretty cool, huh?) So this is the case. I just created a lab environment for my XenDesktop 7. Because of this new classy environment, so I decided to use Server 2012. I have a server act as a DHCP, DNS and DC (have to, not enough resources), and another server as member server. So when I wanted to add this member server to my domain, I received error as in Issue section.



Issues :


  • Facing with this error while adding member server to domain.
    The following error occurred attempting to join the domain <domainName> :
    The specified domain either does not exist or could not be contacted.




Troubleshooting 
  • It turned out that my DNS server is not properly configured. It is not configured to any server, thus resulting member server cannot contact to any DNS server.





Resolution :
  1. Configure the correct DNS server. Depending on your environment, you may want to set it manually at servers, or at Scope option level.
  2.  Perform IPCONFIG /Release and IPCONFIG /Renew, so new configuration will take place. 
  3.  Rejoin the member server to domain, and tadaa!



Reference 

  • http://social.technet.microsoft.com/Forums/windowsserver/en-US/8df10ef3-5789-46cc-9446-40664e56522a/error-message-the-specified-domain-either-does-not-exist-or-could-not-be-contacted?forum=winservergen
Share: