Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created January 6, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFFail/6442b27225eb71b30d26 to your computer and use it in GitHub Desktop.
Save JFFail/6442b27225eb71b30d26 to your computer and use it in GitHub Desktop.
Script to pull the end of netlogon.log files on a list of DCs to check for entries in the last two months.
#Get the list of servers.
$serverList = Get-Content -Path .\servers.txt
#Loop through each.
foreach($server in $serverList) {
#Get the contents of the netlogon file.
$netlogonContent = Get-Content -Path \\$server\C$\Windows\debug\netlogon.log -Tail 5
#Boolean to only write the server name once if at all.
$serverNameWritten = $false
#Make another loop to go through the logs.
foreach($line in $netlogonContent) {
#Check the date.
if($line.Contains("01/") -or $line.Contains("12/"))
{
#See if the server name should be written.
if(-not $serverNameWritten) {
Write-Host $server
Write-Host "========================================"
$serverNameWritten = $true
}
Write-Host $line
}
}
#Write more whitespace for readability *if* the server had any results that needed to be written.
if($serverNameWritten) {
Write-Host " "
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment