May 20 2013

Powershell script to check automatic registration of addresses in DNS



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------

This is nifty PowerShell script to query a list of computer names and then work out whether the “Register this connection’s address in DNS” tick box is ticked for each active NIC.

 

 
##########################################################
#
# Adjustable variables (2)
#
# Specify the name and location of the a text file containing the server names to be scanned, eg $computers = get-content C:tempServer_Names.txt

$computers = get-content C:tempServer_Names.txt

# Specify the name and location of the export CSV file to be created, eg $FileLocation = "c:tempExport.csv"

$FileLocation = "c:tempExport.csv"

##########################################################

# AUTHOR:	blog.danovich.com.au
# DATE:		20/05/2013
# NAME:		DNS_Registration.ps1
# VERSION:	1.1
# PURPOSE:	Query list of servers and return if the "Register this connection's address in DNS" tick box is ticked for each active NIC
# COMMENT:	1.0 Initial release after testing
#				This script checks the FullDNSRegistrationEnabled properties of each network card:
#					If TRUE, the IP addresses for this connection are registered in DNS under the computer's full DNS name.
#			1.1 Added check for remote WMI connectivity. Added listing of DNS servers used for each NIC. Added Connection Name as well as NIC name.

##########################################################

$ErrorActionPreference = "SilentlyContinue"

# Create empty array
$report = @()

# Set count
$i = 0

ForEach ($computer in $computers){

    #Count the computers
	$count = $computers | measure

	# Output progress to screen
    $i++
    $numberofservers = $computers.count
    $ProgressName = $computer
    Write-Progress -Activity "Collecting NIC information" -status "Contacting $computer [$i out of $numberofservers].  Overall percentage complete:" -percentComplete ($i / $computers.count*100)

	# Check WMI connectivity

	$wmi = $null
	$wmi = Get-WmiObject -class Win32_ComputerSystem -ComputerName $computer -ErrorAction SilentlyContinue

	if ($wmi) 
		# Start query if WMI connectivity is true
		{
				#Connect to the Win32_NetworkAdapterConfiguration class using WMI
				$compnetworks = Get-WMIObject -computername $computer -Class Win32_NetworkAdapterConfiguration | Where-Object{$_.IPEnabled -eq $True}

				ForEach($compnetwork in $compnetworks) 
				{

					# Get which DNS Servers are used for queries
					$DNSServers = ""
					ForEach($Address In $compnetwork.DNSServerSearchOrder)
					{$DNSServers += $Address + "  "}		

					# Create object to collect elements

					$OutputObj = New-Object -TypeName PSObject -Property @{
										"Name" = $computer.ToUpper()
										"IP_Address" = $compnetwork.IPAddress
										"Register DNS ticked?" = $compnetwork.FullDNSRegistrationEnabled
										"DNS Servers" = $DNSServers
										"Network Connection" = $($compnetwork.GetRelated("Win32_NetworkAdapter")).NetConnectionId + " (" +  $compnetwork.Description + ")"

					} | Select-Object "Name","Network Connection","IP_Address","Register DNS ticked?","DNS Servers"

					# Convert to exportable format

					$OutputObj | %{$_.IP_Address = [string]$_.IP_Address}

					# Add item to report
					$report += $OutputObj	
				}
		# End query if WMI connectivity is true						
		}
	else
		# Unable to connect to WMI
		{
			# Create object to collect elements
			$OutputObj = New-Object -TypeName PSObject -Property @{
										"Name" = $computer.ToUpper()
										"Description" = "Unable to connect to remote WMI"
										"IP_Address" = "Unable to connect to remote WMI"
										"Register DNS ticked?" = "Unable to connect to remote WMI"               
										"Network Connection" = "Unable to connect to remote WMI"        
			} | Select-Object "Name","Network Connection","IP_Address","Register DNS ticked?","DNS Servers"

		# Add item to report
		$report += $OutputObj	

		# End unable to connect to WMI
		}
	}

# Output findings

$report | Export-Csv $FileLocation -Force -NoTypeInformation
clear
write-host "Done... results exported to" $FileLocation


----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------


Tags: , , , ,

Posted May 20, 2013 by danovich in category "Powershell", "Scripting", "Tools", "Windows

1 COMMENTS :

  1. Pingback: NeWay Technologies – Weekly Newsletter #44 – May 24, 2013 | NeWay

Leave a Reply