{"id":86,"date":"2019-01-04T04:05:23","date_gmt":"2019-01-04T09:05:23","guid":{"rendered":"http:\/\/itblog.ldlnet.net\/?p=86"},"modified":"2019-01-28T20:47:33","modified_gmt":"2019-01-29T01:47:33","slug":"powershell-script-to-log-netlogon-events-5719-and-5783-then-test-the-secure-channel-to-verify-connectivity","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2019\/01\/04\/powershell-script-to-log-netlogon-events-5719-and-5783-then-test-the-secure-channel-to-verify-connectivity\/","title":{"rendered":"PowerShell Script to log NETLOGON Events 5719 and 5783, then test the Secure Channel to verify connectivity"},"content":{"rendered":"\n<p>In my support role, we would get nightly alerts showing disconnection to  the PDC from other DCs and Exchange Servers, giving the following events:<\/p>\n\n\n\n<p><font color=\"blue\">DC02<\/font><br>10\/31\/2018 23:20:28 <font color=\"red\">5719<\/font><br>NETLOGON<br>This computer was not able to set up a secure session with a domain controller in domain LDLNET due to the following:<br>The remote procedure call was cancelled.<br>This may lead to authentication problems. Make sure that this computer is connected to the network. If the problem persists, please contact your domain administrator.<br><br>ADDITIONAL INFO<br>If this computer is a domain controller for the specified domain, it sets up the secure session to the primary domain controller emulator in the specified domain. Otherwise, this computer sets up the<br>secure session to any domain controller in the specified domain.<\/p>\n\n\n\n<p><font color=\"blue\">DC03<\/font><br>10\/31\/2018 23:18:58 <font color=\"red\">5783<\/font><br>NETLOGON<br>The session setup to the Windows NT or Windows 2000 Domain Controller <font color=\"green\">\\\\DC01.LDLNET.ORG<\/font> for the domain LDLNET is not responsive. The current RPC call from Netlogon on <font color=\"green\">\\\\DC03<\/font> to <font color=\"green\">\\\\DC01.ldlnet.org<\/font> has been cancelled.<\/p>\n\n\n\n<p>In order to validate the secure channel, you normally run the nltest command (you can also run the Test-ComputerSecureChannel PowerShell cmdlet) to verify the connectivity to the PDC on the secure channel. The scenario is though that multiple DCs or Exchange servers are having multiple events at a similar time due to a network hiccup that brought the secure channel offline between the two Servers. <br><br>Our team at the time was getting a lot of alerts generated and it was taking an inordinate amount of time to validate and test. In an effort to provide an efficient solution for this issue, I compiled a PowerShell ps1 script to first validate the events posted in the past three hours, and then secondly, test all the DCs and Exchange Servers for the Secure Channel Connectivity:<\/p>\n\n\n\n<p class=\"has-text-color has-small-font-size has-medium-pink-color\">NOTE: This script needs to be run on a server that has the Exchange and Active Directory RSAT tools for PowerShell.<\/p>\n\n\n<pre class=\"lang:PowerShell\" title=\"5719.ps1\">#Start Script\n\u00a0\n#Import Active Directory Module\nWrite-Host\nWrite-Host \"Importing the Active Directory Module\" -ForegroundColor Green\nImport-Module ActiveDirectory\n\n#Import Exchange Module\n    Write-Host \"Loading the Exchange Snap-In\"\n    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue\n    . $env:ExchangeInstallPath\\bin\\RemoteExchange.ps1\n    Connect-ExchangeServer -auto -AllowClobber\n\u00a0\n#Get the list of DCs in the domain\nWrite-Host\nWrite-Host \"Getting the list of DCs for LDLNET\" -ForegroundColor Magenta\n$DCList = Get-ADDomainController -Filter * | Sort-Object Name | Select-Object Name\n\n#Get the list of Exchange Servers in the domain\nWrite-Host\nWrite-Host \"Getting the list of Exchange Servers for LDLNET\" -ForegroundColor Magenta\n$EXList = Get-ExchangeServer | Sort-Object Name | Select-Object Name\n\u00a0\n#Run the command against each server to pull the Events from Event Logging. Make sure you have the StartTime;Endtime parameters correct. This gets events for the past three hours.\nWrite-Host\nWrite-Host \"Getting a list of 5719 and 5783 Events from the DCs for the past three hours.\" -ForegroundColor DarkCyan\nforeach ($DC in $DCList) {\ntry{\n\u00a0\u00a0\u00a0 echo $DC.name\n\u00a0\u00a0\u00a0 $Event = Get-Winevent -ComputerName $DC.name -FilterHashTable @{LogName=\"System\";StartTime=((get-date).addhours(-3));id='5719','5783'} -ErrorAction Stop | foreach {[string]$_.timecreated + \"`t\" + [string] $_.id + \"`n\"\u00a0 + $_.ProviderName + \"`n\" + $_.message + \"`n\"}\n\u00a0\u00a0\u00a0 Write-Host \"$Event\" -ForegroundColor Red \n    }\n\u00a0\u00a0\u00a0 Catch{Write-Host \"No Events Found For This Server\" -ForegroundColor Green\n\t\tWrite-Host}\n}\n\n#Run the command against each server to pull the Events from Event Logging. Make sure you have the StartTime;Endtime parameters correct. This gets events for the past three hours.\nWrite-Host\nWrite-Host \"Getting a list of 5719 and 5783 Events from the Exchange Servers for the past three hours.\" -ForegroundColor DarkCyan\nforeach ($EX in $EXList) {\ntry{\n    echo $EX.Name\n    $Event = Get-Winevent -ComputerName $EX.name -FilterHashTable @{LogName=\"System\";StartTime=((get-date).addhours(-3));id='5719','5783'} -ErrorAction Stop | foreach {[string]$_.timecreated + \"`t\" + [string] $_.id + \"`n\" + $_.ProviderName + \"`n\"\u00a0 + $_.message + \"`n\"}\n     Write-Host \"$Event\" -ForegroundColor Red \n     }\n    Catch{Write-Host \"No Events Found For This Server\" -ForegroundColor Green\n    Write-Host}\n}\n\u00a0\n#Run the Secure Channel Test for the DCs. Make sure you modify the nltest command for your domain fqdn.\nStart-Sleep -Seconds 2\nWrite-Host\nWrite-Host \"Testing Secure Channel for the DCs in LDLNET\" -ForegroundColor Cyan\nforeach ($DC in $DCList) {\ntry{\n\techo $DC.name\n\t$Test = Invoke-Command -ComputerName $DC.Name -ScriptBlock {nltest \/sc_verify:ldlnet.org} -ErrorAction Stop | Out-String -Stream\n\tWrite-Host \"$Test\" -ForegroundColor Yellow \n\t}\n\tCatch{Write-Host \"Secure Channel Test Failed For This Server\" -ForegroundColor Red}\n}\n\n#Run the Secure Channel Test for the Exchange Servers. Make sure you modify the nltest command for your domain fqdn.\nStart-Sleep -Seconds 2\nWrite-Host\nWrite-Host \"Testing Secure Channel for the Exchange Servers in LDLNET\" -ForegroundColor Cyan\nforeach ($EX in $EXList) {\ntry{\n\techo $EX.name\n\t$Test = Invoke-Command -ComputerName $EX.Name -ScriptBlock {nltest \/sc_verify:ldlnet.org} -ErrorAction Stop | Out-String -Stream\n\tWrite-Host \"$Test\" -ForegroundColor Yellow \n\t}\n\tCatch{Write-Host \"Secure Channel Test Failed For This Server\" -ForegroundColor Red}\n}\n\n#End of Script <\/pre>\n\n\n\n<p>I can&#8217;t really put out the output since it will have customer PII, but you will see where it will list the DC\/Exchange Server Name, show the events, then run the test. You can then troubleshoot from there. <em>Also, know that the secure channel test will FAIL when run on the PDC Emulator DC. The PDC Emulator cannot run a secure channel test on itself.<\/em><\/p>\n\n\n\n<p style=\"text-align:center\" class=\"has-text-color has-bright-blue-color\"><strong>Please, if you have any questions or comments, please leave some feedback! Happy Troubleshooting! <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my support role, we would get nightly alerts showing disconnection to the PDC from other DCs and Exchange Servers, giving the<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2019\/01\/04\/powershell-script-to-log-netlogon-events-5719-and-5783-then-test-the-secure-channel-to-verify-connectivity\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2,3,16],"tags":[44,45,41,40,43,9,54,8,13],"class_list":["post-86","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-general","category-powershell","category-windows","tag-44","tag-45","tag-active-directory","tag-ad","tag-event-id","tag-exchange","tag-netlogon","tag-powershell","tag-script","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":6,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/86\/revisions\/168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}