<?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>Get Last Logon Date Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/get-last-logon-date/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/get-last-logon-date/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Tue, 26 Oct 2021 23:36:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Get Last Logon Date For All Users in Your Domain</title>
		<link>https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/</link>
					<comments>https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Mon, 18 Jun 2018 03:56:48 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Get Last Logon Date]]></category>
		<category><![CDATA[LastLogon example]]></category>
		<category><![CDATA[LastLogon vs LastLogonDate vs LastLogonTimeStamp]]></category>
		<category><![CDATA[LastLogonDate example]]></category>
		<category><![CDATA[What is last logon in Active Directory]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=662</guid>

					<description><![CDATA[<p>Get Last Logon Date For All Users in Your Domain. It seems simple right? In many of the environments I&#8217;ve walked into there have been users that haven&#8217;t logged into the domain in a certain number of months. Some users&#8230; <a href="https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/">Get Last Logon Date For All Users in Your Domain</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Get Last Logon Date For All Users in Your Domain.  It seems simple right? In many of the environments I&#8217;ve walked into there have been users that haven&#8217;t logged into the domain in a certain number of months.  Some users more recent than others but I have seen some as bad as a couple of years, yet the accounts were still not disabled. For me personally, this is probably one of my biggest pet peeves.  </p>
<p>I don&#8217;t know why, but I don&#8217;t like to see stale accounts just there in the mix with all the accounts that logon on a regular basis.  I understand that some can be lab accounts, others can be test accounts that get used from time to time but for the most part, it&#8217;s Nancy from Accounting that quit 3 years ago and her account is still being used by Mary because there wasn&#8217;t a proper term procedure in place.  </p>
<p>We&#8217;ll get to the automation of the term procedure in another post but this should be done.  For one, it&#8217;s a huge SOX violation and two,  it gives you a better overview of what&#8217;s in your environment.  So for this, we will use the <code>LastLogonDate</code> and <code>LastLogon</code> attributes in Active Directory to get last logon date for users in your domain.</p>
<h2>What is last logon in Active Directory</h2>
<p>So what is last logon in Active Directory?  In simple terms, it&#8217;s a time stamp representation of the last time a domain controller successfully authenticated the user or computer object. </p>
<p>There are 3 basic attributes that tell you when the last time an object last authenticated against a Domain Controller.  They are the <strong>LastLogonDate</strong>, <strong>LastLogon</strong> and the <strong>LastLogonTimeStamp</strong>.</p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2018/06/LastLogonAttributes_1.png" target="_blank" rel="noopener noreferrer"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2018/06/LastLogonAttributes_1.png" alt="Las tLogon Attribute Active Directory" width="1058" height="529" class="alignleft size-full wp-image-2318" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/06/LastLogonAttributes_1.png?v=1600538610 1058w, https://thesysadminchannel.com/wp-content/uploads/2018/06/LastLogonAttributes_1-1024x512.png?v=1600538610 1024w, https://thesysadminchannel.com/wp-content/uploads/2018/06/LastLogonAttributes_1-768x384.png?v=1600538610 768w" sizes="(max-width: 1058px) 100vw, 1058px" /></a></p>
<h2>LastLogon vs LastLogonTimeStamp vs LastLogonDate</h2>
<p>If you&#8217;ve been doing your research I&#8217;m sure you&#8217;ve come across articles saying to use LastLogonTimeStamp because it replicates across all DCs and gives you a more accurate reading of when the last time the user logged on.  However, this may not always be the case, simply because it only updates when &#8220;it feels like it&#8221; to put it into lamens terms.  LastLogonTimeStamp will give you a rough ballpark of about 2 weeks to see when the user has logged on. When querying the LastLogonTimeStamp, it also uses an unconverted timestamp so we would have to do some Powershell magic to convert it to something our brains understand.</p>
<p>The LastLogonDate is a replica of the LastLogonTimeStamp, however, the output is a human readable date format that we can understand.  I should also note that this attribute is not only used for the logins, but rather the last time it accessed something on the network.  So for example,  let&#8217;s say Johnny, the remote sales guy, is only able to use VPN to connect to the network.  </p>
<p>When he initially fires up his laptop and logs in, he is logging in with his cached credentials so he will never need authenticate to a DC, thus a LastLogon attribute won&#8217;t necessarily get updated.  It could have been years since he was at HQ and actually authenticated against a DC to login so sometimes this is not always accurate either.  </p>
<div id="blockquote1">
<strong>Note:</strong> LastLogonDate has a +/- 2 week representation of when the object was last active.  It&#8217;s human readable and also replicates to all other Domain Controllers so it&#8217;s my preferred attribute for checking last logon dates.
</div>
<p>This is why I prefer to use the LastLogonDate attribute because even though Johnny never authenticated against a DC, he was still using resources on the network so his LastLogonDate attribute will get updated.  I should note that just like LastLogonTimeStamp, LastLogonDate doesn&#8217;t get updated every single the user logs in.  It will give you a 2 week window of when they last accessed something on the network.  Whether it be email, network drives, remote desktop etc.. </p>
<h2>Get Last Logon Date with Powershell</h2>
<p>So there are a couple of ways we can tackle this problem.  If we&#8217;re only querying a single user I would say it&#8217;s best to use the LastLogon attribute because we can query against multiple DCs to get the most updated login attribute.  If we&#8217;re querying multiple users (everything in the domain for example) we should be using the LastLogonDate attribute because it will not bog down the DC with requests and the results can be output fairly quickly.  So how can we achieve this?</p>
<h3>LastLogon Example with Powershell</h3>
<pre class="brush: powershell; title: ; notranslate">

Get-ADUser pcontreras -Properties lastLogon | Select samaccountname, @{Name=&quot;lastLogon&quot;;Expression={[datetime]::FromFileTime($_.'lastLogon')}}

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogon.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogon-1024x491.png" alt="Get-LastLogon" width="1024" height="491" class="aligncenter size-medium wp-image-663" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogon-1024x491.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogon-768x368.png 768w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogon.png 1027w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
&nbsp;</p>
<h3>LastLogonDate Example with Powershell</h3>
<pre class="brush: powershell; title: ; notranslate">

Get-ADUser pcontreras -Properties LastLogonDate | select samaccountname, lastlogondate

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogonDate.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogonDate-1024x491.png" alt="Get-LastLogonDate" width="1024" height="491" class="aligncenter size-medium wp-image-665" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogonDate-1024x491.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogonDate-768x368.png 768w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-LastLogonDate.png 1027w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
&nbsp;</p>
<h3>How To Get Last Logon Date for All Users in the Domain</h3>
<pre class="brush: powershell; title: ; notranslate">
#Getting users who haven't logged in in over 90 days
$Date = (Get-Date).AddDays(-90)

#Filtering All enabled users who haven't logged in.
Get-ADUser -Filter {((Enabled -eq $true) -and (LastLogonDate -lt $date))} -Properties LastLogonDate | select samaccountname, Name, LastLogonDate | Sort-Object LastLogonDate

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-ADUser-Filter.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-ADUser-Filter-1024x459.png" alt="Get-ADUser -Filter" width="1024" height="459" class="aligncenter size-medium wp-image-672" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-ADUser-Filter-1024x459.png 1024w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-ADUser-Filter-768x344.png 768w, https://thesysadminchannel.com/wp-content/uploads/2018/06/Get-ADUser-Filter.png 1137w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
&nbsp;</p>
<p>Hopefully this article helped you figure out which attribute is best to use when you want to Get Last Logon Date for your users.  I also hope it gave you an example of why  which should be used.  </p>
<p>Don&#8217;t forget to check our <a href="https://www.youtube.com/channel/UC9VnUjmZrNG3ithDZmG-S-g" target="_blank" rel="noopener noreferrer">Youtube Channel</a> and subscribe if you want more awesome video content.  Somtimes the articles I post don&#8217;t have videos and sometimes the videos I post don&#8217;t have articles so check us out on the big YT to get awesome sysadmin content all around.</p>
<p>The post <a href="https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/">Get Last Logon Date For All Users in Your Domain</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/get-last-logon-date-for-all-users-in-your-domain/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">662</post-id>	</item>
	</channel>
</rss>
