Active Directory NO_CLIENT_SITE report

Written by Arne Tiedemann on Friday June 22, 2018

As an Active Directory administrator, you have to do recurring tasks. One task is to check if client subnets are pointed to an Active Directory site and if not Domain Controllers will log this message in the following log file and print a warning message at the event log.

EventLog ID: 5807 
EventLog Source: NETLOGON
EventLog Message:

During the past <hours> hours there have been <Number> connections to this Domain Controller from client machines whose IP addresses don't map to any of the existing sites in the enterprise. 
Those clients, therefore, have undefined sites and may connect to any Domain Controller including those that are in far distant locations from the clients. 
A client's site is determined by the mapping of its subnet to one of the existing sites. 
To move the above clients to one of the sites, please consider creating subnet object(s) covering the above IP addresses with mapping to one of the existing sites.  

The names and IP addresses of the clients in question have been logged on this computer in the following log file '%SystemRoot%\debug\netlogon.log' and, potentially, in the log file '%SystemRoot%\debug\netlogon.bak' created if the former log becomes full. 
The log(s) may contain additional unrelated debugging information. 
To filter out the needed information, please search for lines which contain text 'NO_CLIENT_SITE:'.
The first word after this string is the client name and the second word is the client IP address.
The maximum size of the log(s) is controlled by the following registry DWORD value 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\LogFileMaxSize'; the default is 20000000 bytes.  The current maximum size is 20000000 bytes.  To set a different maximum size, create the above registry value and set the desired maximum size in bytes.

To get a list of Client IP Addresses that do not belong to an Active Directory Site, you can run this code snippet.



Import-Module -Name ActiveDirectory
$OU = (Get-ADDomain).DomainControllersContainer
$DomainControllers = Get-ADComputer -Filter * -SearchBase $OU
$PathNetlogon = 'Admin$\debug\netlogon.log'
$Pattern = 'NO_CLIENT_SITE'
[Object]$Content = $null

foreach($DomainController in $DomainControllers) {

    # Define Path
    $Path = ('\\{0}\{1}' -f $DomainController.DNSHostName, $PathNetlogon)

    # Check Path
    if (Test-Path -Path $Path -ErrorAction SilentlyContinue) {
        
        Write-Host ('Getting logs from Server {0}:' -f $DomainController.Name) -ForegroundColor Green

        $Rows = Get-Content -Path $Path | Select-String -Pattern $Pattern 

        # Add Lines to variable
            $Content += $Rows
    }
}

$Content | ConvertFrom-Csv -Delimiter ' ' -Header 'Date','Time','Id1','Domain','Type','Client','IPAddress' | Export-Csv -Delimiter ',' -Path $HOME\Documents\NO_CLIENT_SITE.csv -NoTypeInformation

# Sort object
$ExpClientIP = @{Name='IP';Expression={$(if ($_.Client -notmatch '[a-zA-Z]') { $Client = ''; $Client = $_.Client.Split('.'); ('{0}.{1}.{2}' -f $Client[0], $Client[1], $Client[2]) })}}
Import-Csv -Path $HOME\Documents\NO_CLIENT_SITE.csv | Select-Object -Property $ExpClientIP | Where-Object { $_.IP -like '*' } | Group-Object -Property IP | Sort-Object Count | Select-Object Count, Name

Have fun...