<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>event log | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/event-log/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:20:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>event log | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>Checking Why A Remote Computer is Shutdown or Restarted</title>
		<link>https://www.kjctech.net/checking-why-a-remote-computer-is-shutdown-or-restarted/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=checking-why-a-remote-computer-is-shutdown-or-restarted</link>
					<comments>https://www.kjctech.net/checking-why-a-remote-computer-is-shutdown-or-restarted/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Tue, 03 May 2022 05:06:04 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[event log]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4738</guid>

					<description><![CDATA[<p>For Windows computers, every shutdown or restart is logged in the Event Viewer so you know what exactly happened, whether it&#8217;s a system triggered reboot, or by a user specifically, or a restart because of a system or application crash. So, if you want to dig into this information, all you need is to open Event Viewer, head into System [&#8230;]</p>
The post <a href="https://www.kjctech.net/checking-why-a-remote-computer-is-shutdown-or-restarted/">Checking Why A Remote Computer is Shutdown or Restarted</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>For Windows computers, every shutdown or restart is logged in the Event Viewer so you know what exactly happened, whether it&#8217;s a system triggered reboot, or by a user specifically, or a restart because of a system or application crash.</p>



<p>So, if you want to dig into this information, all you need is to open Event Viewer, head into System under Windows logs, and filter out these specific event IDs.</p>



<ul class="wp-block-list"><li>Event ID 41 &#8211; indicating that the computer rebooted without shutting down completely.</li><li>Event ID 1074 &#8211; indicating that a reboot was triggered by an application, including when a user restarted or shut down their computer from the Start Menu or by using Ctrl + Alt + Del.</li><li>Event ID 1076 &#8211; records the reason why the computer was shut down or restarted. It&#8217;s recorded by the first user with shutdown privilege who logs on to the computer after an unexpected restart.</li><li>Event ID 6006 &#8211; indicating whether the computer shuts down correctly.</li><li>Event ID 6008 &#8211; indicating whether the computer shuts down abnormally or unexpectedly.</li></ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="600" height="395" src="//i0.wp.com/kjctech.net/wp-content/uploads/2022/05/image-600x395.png" alt="" class="wp-image-4741" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=600%2C395&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=450%2C297&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=250%2C165&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=520%2C343&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=360%2C237&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?resize=100%2C66&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image.png?w=622&amp;ssl=1 622w" sizes="(max-width: 600px) 100vw, 600px" /></figure>



<p>But I am not going to lie, it&#8217;s quite the work to dig out this information, especially on a remote computer. This is another place where PowerShell really shines in its own way.</p>



<p><strong>Get-EventLog</strong> is the cmdlet that pulls event logs not only from your local computer but remote computers on the same network as well.</p>



<p>To pull the system log from a remote computer called Backup,</p>



<pre class="wp-block-preformatted">Get-EventLog -LogName System -ComputerName Backup</pre>



<p>The list might be too long. So let&#8217;s only pull the logs after Jan 1, 2022.</p>



<pre class="wp-block-preformatted">Get-EventLog -LogName System -ComputerName Backup -After "2022/01/01"</pre>



<p>Now here comes the tricky part, how do I find out these specific events based on the above Event IDs? There are no options to filter out directly so we need to pipe the result through.</p>



<pre class="wp-block-preformatted">Get-EventLog -LogName System -ComputerName Backup -After "2022/01/01" | Where-Object {$_.EventID -in (1074,1076,6006,6008)}</pre>



<p>One more thing, let&#8217;s format the output a bit to show the full event message without being cut off.</p>



<pre class="wp-block-preformatted">Get-EventLog -LogName System -ComputerName Backup -After "2022/01/01" | Where-Object {$_.EventID -in (1074,1076,6006,6008)} | Format-Table TimeGenerated, EventID, Message -Wrap</pre>



<figure class="wp-block-image size-large"><img decoding="async" width="600" height="162" src="//i0.wp.com/kjctech.net/wp-content/uploads/2022/05/image-1-600x162.png" alt="" class="wp-image-4743" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=600%2C162&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=450%2C121&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=250%2C67&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=768%2C207&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=700%2C189&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=520%2C140&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=360%2C97&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?resize=100%2C27&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2022/05/image-1.png?w=1115&amp;ssl=1 1115w" sizes="(max-width: 600px) 100vw, 600px" /></figure>The post <a href="https://www.kjctech.net/checking-why-a-remote-computer-is-shutdown-or-restarted/">Checking Why A Remote Computer is Shutdown or Restarted</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/checking-why-a-remote-computer-is-shutdown-or-restarted/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4738</post-id>	</item>
		<item>
		<title>How To Get the Data Out of ReplacementStrings Properly</title>
		<link>https://www.kjctech.net/how-to-get-the-data-out-of-replacementstrings-properly/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-the-data-out-of-replacementstrings-properly</link>
					<comments>https://www.kjctech.net/how-to-get-the-data-out-of-replacementstrings-properly/#comments</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Thu, 26 Jul 2018 23:58:54 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[event log]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4154</guid>

					<description><![CDATA[<p>When retrieving data from the event log, there is a set of data stored in a data field called ReplacementStrings that is very useful to the certain types of log entries. It&#8217;s structured as a string array, therefore, can be retrieved if you know the data structure. The problem is, every type of event ID has different string array structure. [&#8230;]</p>
The post <a href="https://www.kjctech.net/how-to-get-the-data-out-of-replacementstrings-properly/">How To Get the Data Out of ReplacementStrings Properly</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>When retrieving data from the event log, there is a set of data stored in a data field called ReplacementStrings that is very useful to the certain types of log entries. It&#8217;s structured as a string array, therefore, can be retrieved if you know the data structure.</p>



<p>The problem is, every type of event ID has different string array structure. So you need to exam each of them separately. To find a certain type of event ID&#8217;s structure, open one of the log entry, switch to <strong>Details</strong> tab and look at the <strong>EventData</strong> section. </p>



<p>Take an event ID 4740 entry as an example. It lays out as it&#8217;s structured, starting from 0, which is TargetUserName, the user account that gets locked out. The next one will be 1 for <g class="gr_ gr_96 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="96" data-gr-id="96">TargetDomainName</g>, the computer where the account gets locked out.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" decoding="async" width="640" height="445" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=640%2C445&#038;ssl=1" alt="" class="wp-image-4157" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?w=640&amp;ssl=1 640w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=250%2C174&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=450%2C313&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=600%2C417&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=520%2C362&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=360%2C250&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-3.png?resize=100%2C70&amp;ssl=1 100w" sizes="(max-width: 640px) 100vw, 640px" /></figure>



<p>So you can retrieve the data and display them accordingly, using ReplacementString[0] to get the data for TargetUserName and ReplacementString[1] for TargetDomainName.</p>



<p>Here is a script that retrieves lockout account info from the security event log, for your reference.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">#Collect lockout accounts from ADS

$logname = "security"
$dcname = (Get-AdDomain).pdcemulator
$eventID = "4740"
$content = Get-EventLog -LogName $logname -ComputerName $dcname -After (Get-Date).AddDays(-1) -InstanceId $eventID | Select TimeGenerated, ReplacementStrings
$ofs = "`r`n`r`n"
$body = "Fetching event log started on " + (Get-Date) + $ofs

If ($content -eq $null)
{
    $body = $body + "No lock-out accounts happened today" + $ofs
}
Else 
{
    Foreach ($event in $content)
    {
        $source = $content.ReplacementStrings[1]
        $username = $content.ReplacementStrings[0]
        $body = $body + $event.TimeGenerated + ": " + $username + " - " + $source + $ofs
    }
}
$body</code></pre>



<p>Hope it helps.</p>The post <a href="https://www.kjctech.net/how-to-get-the-data-out-of-replacementstrings-properly/">How To Get the Data Out of ReplacementStrings Properly</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/how-to-get-the-data-out-of-replacementstrings-properly/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4154</post-id>	</item>
		<item>
		<title>Gather Bad Password Attempts and Account Lockout Info in PowerShell</title>
		<link>https://www.kjctech.net/gather-bad-password-attempts-and-account-lockout-info-in-powershell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gather-bad-password-attempts-and-account-lockout-info-in-powershell</link>
					<comments>https://www.kjctech.net/gather-bad-password-attempts-and-account-lockout-info-in-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Thu, 26 Jul 2018 06:26:53 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[event log]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4149</guid>

					<description><![CDATA[<p>If a user account gets locked out, I can follow these tips to find out why and when it happened. But how can I check and gather lockout info along with the bad password attempts info of all users across the entire AD domain? Asking help from PowerShell is my answer. There are two places where we can gather this [&#8230;]</p>
The post <a href="https://www.kjctech.net/gather-bad-password-attempts-and-account-lockout-info-in-powershell/">Gather Bad Password Attempts and Account Lockout Info in PowerShell</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>If a user account gets locked out, I can follow t<a href="https://www.kjctech.net/why-my-windows-active-directory-domain-account-is-locked-out/">hese tips</a> to find out why and when it happened. But how can I check and gather lockout info along with the bad password attempts info of all users across the entire AD domain?</p>



<p>Asking help from PowerShell is my answer.</p>



<p>There are two places where we can gather this information. The AD contains the bad password attempts and the lockout status while the security event log saves the user account lockout information when it happens.</p>



<p>To get bad password attempts info from AD, use <strong>Get-ADUser</strong> cmdlet.</p>



<pre class="wp-block-preformatted">Get-ADUser -Filter * -Properties AccountLockoutTime,LastBadPasswordAttemptBadPwdCount,LockedOut</pre>



<p>If you want just the info for the past day, pipe the result to Where clause.</p>



<pre class="wp-block-preformatted">Get-ADUser -Filter * -Properties AccountLockoutTime,LastBadPasswordAttemptBadPwdCount,LockedOut | Where {$_.LastBadPasswordAttempt -gt (Get-Date).AddDays(-1)}<br/></pre>



<p>To get the account lockout info, use <strong>Get-EventLog</strong> cmd to find all entries with the event ID 4740. Use -After switch to narrow down the date.</p>



<pre class="wp-block-preformatted">Get-EventLog -LogName "Security" -ComputerName "AD_Server" -After (Get-Date).AddDays(-1) -InstanceID "4740" | Select TimeGenerated, ReplacementString<br/></pre>



<p>Depending on the size of the log file, it could take a while to get all the result.</p>



<p>Going through the result, you may find the data shown on the screen is incomplete. That&#8217;s because the <strong>ReplacementString</strong> is a string array that contains the event log data in an XML type of format. Each event type has its own string structure. For 4740 events, </p>



<ul class="wp-block-list"><li>ReplacementString[0] stores the name of the computer where the account gets locked out and </li><li>ReplacementString[1] indicates the name of the user account that gets locked out.</li></ul>



<p>So, instead of running the above cmdlet, the following script provides a lot more clear useful info.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">#Collect lockout accounts from ADS

$logname = "security"
$dcname = (Get-AdDomain).pdcemulator
$eventID = "4740"
$content = Get-EventLog -LogName $logname -ComputerName $dcname -After (Get-Date).AddDays(-1) -InstanceId $eventID | Select TimeGenerated, ReplacementStrings
$ofs = "`r`n`r`n"
$body = "Fetching event log started on " + (Get-Date) + $ofs

If ($content -eq $null)
{
    $body = $body + "No lock-out accounts happened today" + $ofs
}
Else 
{
    Foreach ($event in $content)
    {
        $source = $content.ReplacementStrings[1]
        $username = $content.ReplacementStrings[0]
        $body = $body + $event.TimeGenerated + ": " + $username + " - " + $source + $ofs
    }
}
$body</code></pre>



<p>Hope it helps.</p>The post <a href="https://www.kjctech.net/gather-bad-password-attempts-and-account-lockout-info-in-powershell/">Gather Bad Password Attempts and Account Lockout Info in PowerShell</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/gather-bad-password-attempts-and-account-lockout-info-in-powershell/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4149</post-id>	</item>
	</channel>
</rss>
