<?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>Edwin M Sarmientoconvert 64-bit value &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/category/convert-64-bit-value/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>One-liner in PowerShell? Convert a 64-bit (Integer8) value to date time</title>
		<link>https://www.edwinmsarmiento.com/one-liner-in-powershell-convert-a-64-bit-integer8-value-to-date-time/</link>
		<comments>https://www.edwinmsarmiento.com/one-liner-in-powershell-convert-a-64-bit-integer8-value-to-date-time/#respond</comments>
		<pubDate>Tue, 08 Jul 2008 10:01:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[convert 64-bit value]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2008/07/08/one-liner-in-powershell-convert-a-64-bit-integer8-value-to-date-time</guid>

				<description><![CDATA[As I was converting my VBScripts to PowerShell, I reviewed one which checks for the password expiration of a user in Active Directory. The blog post I&#8217;ve had sometime last year extracts object properties and one of them is the pwdLastSet property which specifies a 64-bit value of when the user last changed their passwords. [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">As I was converting my VBScripts to PowerShell, I reviewed one which checks for the password expiration of a user in Active Directory. The <a href="http://bassplayerdoc.blogspot.com/2007/11/identify-password-expiration-in-active.html">blog post </a>I&#8217;ve had sometime last year extracts object properties and one of them is the <strong><span style="font-size:85%;">pwdLastSet</span></strong> property which specifies a 64-bit value of when the user last changed their passwords. This is necessary if you need to know how many days left before their password expires. One of the things I did was to use a function that converts the 64-bit value to a valid date/time value</span> &#8211; <span style="font-family:arial;">thanks to Richard Mueller, of course.</span></p>
<p><strong><span style="font-size:85%;"><span style="color:blue;">Function </span><span style="color:black;">Integer8Date</span><span style="color:gray;">(</span><span style="color:blue;">ByVal </span><span style="color:black;">objDate</span><span style="color:gray;">, </span><span style="color:blue;">ByVal </span><span style="color:black;">lngBias</span></span></strong><span style="font-size:85%;color:gray;"><strong>)<br />
</strong></span><strong><span style="font-size:85%;"><span style="color:green;">&#8216; Function to convert Integer8 (64-bit) value to a date, adjusted for<br />
&#8216; local time zone bias.<br />
</span><span style="color:blue;">Dim </span><span style="color:black;">lngAdjust</span><span style="color:gray;">, </span><span style="color:black;">lngDate</span><span style="color:gray;">, </span><span style="color:black;">lngHigh</span><span style="color:gray;">, </span></span></strong><strong><span style="font-size:85%;"><span style="color:black;">lngLow<br />
lngAdjust </span><span style="color:blue;">= </span></span></strong><strong><span style="font-size:85%;"><span style="color:black;">lngBias<br />
lngHigh </span><span style="color:blue;">= </span></span></strong><strong><span style="font-size:85%;"><span style="color:black;">objDate.HighPart<br />
lngLow </span><span style="color:blue;">= </span></span></strong><span style="font-size:85%;color:black;"><strong>objdate.LowPart<br />
</strong></span><strong><span style="font-size:85%;"><span style="color:green;">&#8216; Account for bug in IADslargeInteger property methods.<br />
</span><span style="color:blue;">If </span><span style="color:gray;">(</span><span style="color:black;">lngLow </span><span style="color:gray;">&lt; </span><span style="color:black;">0</span><span style="color:gray;">) </span></span></strong><strong><span style="font-size:85%;"><span style="color:blue;">Then<br />
</span><span style="color:black;">lngHigh </span><span style="color:blue;">= </span><span style="color:black;">lngHigh </span><span style="color:gray;">+ </span></span></strong><span style="font-size:85%;color:black;"><strong>1<br />
</strong></span><strong><span style="font-size:85%;"><span style="color:blue;">End If</span></span></strong></p>
<p>If <span style="color:gray;">(</span><span style="color:black;">lngHigh </span><span style="color:blue;">= </span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:blue;">And </span><span style="color:gray;">(</span><span style="color:black;">lngLow </span><span style="color:blue;">= </span><span style="color:black;">0</span><span style="color:gray;">) </span><strong><span style="font-size:85%;"><span style="color:blue;">Then<br />
</span><span style="color:black;">lngAdjust </span><span style="color:blue;">= </span></span></strong><span style="font-size:85%;color:black;"><strong>0<br />
</strong></span><strong><span style="font-size:85%;"><span style="color:blue;">End If</span></span></strong></p>
<p><span style="color:black;">lngDate </span><span style="color:blue;">= </span><span style="color:black;">#1</span><span style="color:gray;">/</span><span style="color:black;">1</span><span style="color:gray;">/</span><span style="color:black;">1601# </span><span style="color:gray;">+ (((</span><span style="color:black;">lngHigh </span><span style="color:gray;">* (</span><span style="color:black;">2 </span><span style="color:gray;">^ </span><span style="color:black;">32</span><span style="color:gray;">)) </span><strong><span style="font-size:85%;"><span style="color:black;">_<br />
</span><span style="color:gray;">+ </span><span style="color:black;">lngLow</span><span style="color:gray;">) / </span><span style="color:black;">600000000 </span><span style="color:gray;">&#8211; </span><span style="color:black;">lngAdjust</span><span style="color:gray;">) / </span></span></strong><strong><span style="font-size:85%;"><span style="color:black;">1440</span></span></strong></p>
<p>Integer8Date <span style="color:blue;">= CDate</span><span style="color:gray;">(</span><span style="color:black;">lngDate</span><strong><span style="font-size:85%;"><span style="color:gray;">)<br />
</span><span style="color:blue;">End Function</span> </span></strong></p>
<p><span style="font-family:arial;">I pass the value from <strong><span style="font-size:85%;">pwdLastSet</span></strong> property to this function to get the date/time value. After a couple of Google searches, I chanced upon a forum post by <a href="https://mvp.support.microsoft.com/profile/Brandon">Brandon Shell &#8211; Microsoft PowerShell MVP</a>. The entire function can be summed up in just a line</span></p>
<pre class="brush: powershell; title: ; notranslate">
&#x5B;datetime]::FromFileTimeUTC($objItem.pwdlastset&#x5B;0])
</pre>
<p><strong></strong><br />
<span style="font-family:arial;">This is if you are using the <strong><span style="font-size:85%;"><a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.aspx">System.DirectoryServices.DirectorySearcher</a></span></strong> class and not the<br />
<strong><span style="font-size:85%;"><a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx">System.DirectoryServices.DirectoryEntry</a></span></strong> in the .NET Framework which is available in PowerShell. The <strong><span style="font-size:85%;"><a href="http://msdn.microsoft.com/en-us/library/system.datetime.fromfiletimeutc.aspx">DateTime.FromFileTimeUtc</a></span></strong> Method converts the specified Windows file time to an equivalent UTC time. So much for using conversion functions in VBScript to do this.</span></p>
<div class="blogger-post-footer"><img alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/one-liner-in-powershell-convert-a-64-bit-integer8-value-to-date-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">115</post-id>	</item>
	</channel>
</rss>