no_client_site reporting in AD

$DCS= Get-Content -Path C:\Users\XXX\Desktop\DCS.txt

foreach ($DC in $DCS)
{

$importString = Import-Csv \$DC\admin$\debug\netlogon.log -Delimiter ’ ’ -Header Date,Time,Domain,Error,Name,Hostname,IPAddress -Verbose

$importString | Where-Object {$_.Name -eq “NO_CLIENT_SITE:”} |sort Hostname -Unique |select Hostname,IPAddress >> C:\ncs.txt -Verbose
}

Running the above script I am able to get the output as desired just if anyone can help me get the DC name as well in the output.

Hostname IPAddress


XXXXXXXXX XXXXXXX
XXXXXXXXX XXXXXXX

Hostname IPAddress


XXXXXX XXXXX
XXXXXX XXXXX

what I want is something like this

Hostname IPAddress DCName
-------- --------- xxxx
xxxxxxx xxxxxxxxx
xxxxxx xxxxxxxxxxxxx

Thanks in advance.

$importString | Where-Object {$_.Name -eq "NO_CLIENT_SITE:"} |sort Hostname -Unique |select Hostname,IPAddress, @{Label = "DCName"; Expression = {$DC}} >> C:\ncs.txt -Verbose

Thank you so much Curtis. Really appropriate your help.

If I try to use some error handleing in this, to report those dc’s which doesnt have any no_cilnet_site what would be the option. I tried using try catch but doesnt help. Even tried using if else but that didnt work as well, Can someone plz help. Also we have a large no of dc in our env (98), could there can be any catch to speed up the script ? When I tried this with only three dc it takes near about 15 min. Though we have very good wan bandwidth. Thanks in advance.

You could use Test-Connection to see if the DC is online before you try accessing the netlogon.log via UNC path.

Thanks again Curtis, however I am looking for something by which I can generate a log which tells us if the DC doesn’t contains any no_client_site.

$DCS=Get-Content C:\Users\XXXX\Desktop\computers.txt
foreach ($dc in $dcs)

{

$netlogon= Get-Content -path \$DC\admin$\debug\netlogon.log

if ($netlogon.contains(“NO_CLIENT_SITE:”))

{
$importString = Import-Csv \$DC\admin$\debug\netlogon.log -Delimiter ’ ’ -Header Date,Time,Domain,Error,Name,Hostname,IPAddress -Verbose

$importString | Where-Object {$_.Name -eq “NO_CLIENT_SITE:”} |sort Hostname -Unique |select Hostname,IPAddress, @{Label = “DCName”; Expression = {$DC}} >> D:\Partho\ncs.txt
}

else { “no record found for $DC” >> D:\Partho\ncslog.txt}

}

I have tried using this but that didn’t work.

Sorry, misread your previous post. I thought you were wanting to check for a DC that was offline so that it would not delay the script waiting for a timeout.

Anyway you would need to collect your results and then test to see if there are any. Something similar to the following

$DCS= Get-Content -Path C:\Users\XXX\Desktop\DCS.txt

foreach ($DC in $DCS)
{
    $importString = Import-Csv \\$DC\admin$\debug\netlogon.log -Delimiter ' ' -Header Date,Time,Domain,Error,Name,Hostname,IPAddress -Verbose
    $NoClientSites = $importString | Where-Object {$_.Name -eq "NO_CLIENT_SITE:"} | sort Hostname -Unique |select Hostname,IPAddress

    If ($NoClientSites) {
        $NoClientSites | Out-File C:\ncs.txt -Append
    }#if
    Else {
        "No Records found on $DC" | Out-File C:\ncs.txt -Append
    }#else
}

Excellent Curtis, You saved my day.