no_client_site reporting in AD

This topic contains 8 replies, has 2 voices, and was last updated by Profile photo of Partho Sankar Roy Partho Sankar Roy 1 year, 8 months ago.

  • Author
    Posts
  • #30097
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    $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.

  • #30098
    Profile photo of Curtis Smith
    Curtis Smith
    Participant
    $importString | Where-Object {$_.Name -eq "NO_CLIENT_SITE:"} |sort Hostname -Unique |select Hostname,IPAddress, @{Label = "DCName"; Expression = {$DC}} >> C:\ncs.txt -Verbose
    
  • #30099
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    Thank you so much Curtis. Really appropriate your help.

  • #30108
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    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.

  • #30142
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

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

  • #30150
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    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.

  • #30151
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    $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.

  • #30152
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    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
    }
    
  • #30153
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    Excellent Curtis, You saved my day.

You must be logged in to reply to this topic.