Convert Int64 TimeStamp To DateTime In Powershell

Skip to content Menu Some Applications (Ex: Active Directory ) stores DateTime value as TimeStamp value in a way to support different time zone. The Int64 TimeStamp is nothing but Windows file time. The Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC).

In Powershell, we can use the .Net function FromFileTime and convert the output to DateTime format.

$timestamp = "131099683087123361" [DateTime]::FromFileTimeutc($timestamp)

You can also convert the standard datetime to timestamp value by using the function ToFileTimeUtc.

$date = Get-Date $date.ToFileTimeUtc()

In Active Directory environment, the attributes LastLogonTimeStamp and PwdLastSet are stored as Int64 TimeStamp. When you query these properties by using Get-ADUser cmdlet, you need to explicitly convert LastLogonTimeStamp value into datetime value.

Get-ADUser -Identity 'Smith' -Properties LastLogonTimeStamp | Select-Object -Property "Name", @{n="LastLogon";e={[datetime]::FromFileTime($_."LastLogonTimeStamp")}}

The following powershell command convert AD user’s PwdLastSet value to datetime value.

Get-ADUser -Identity 'Smith' -Properties PwdLastSet | Select-Object -Property "Name", @{n="PwdLastSet";e={[datetime]::FromFileTime($_."PwdLastSet")}}

Share this:

  • Facebook
  • X

Related Posts

  • PowerShell - Convert Large Integer value to DateTime string
  • Powershell : Convert SecureString to Plain Text
  • PowerShell - Convert Ticks to DateTime and Vise Versa
  • Convert SID to Username using Powershell
  • Convert CSV string to PS Object in PowerShell
Advertisement

1 thought on “Convert Int64 TimeStamp to DateTime in Powershell”

  1. It works fine, thanks a lot for the trick 🙂

    Reply

Leave a Comment Cancel reply

Comment

Name Email Website

Save my name, email, and website in this browser for the next time I comment.

Δ

Categories

  • Powershell
  • Microsoft 365
  • Azure AD
  • SharePoint Online
  • Exchange Online
  • Microsoft Teams
  • Office 365 Groups
  • Active Directory
  • Microsoft Graph
  • PnP-PowerShell
  • CSOM

Recent Posts

  • Get Azure AD (Entra ID) App-Only Access Token with PowerShell
  • Working with REST API in PowerShell using Invoke-RestMethod
  • M365 User SignIn Activity – Neither tenant is B2C or tenant doesn’t have premium license
  • How to Join or Concatenate String and Number Using PowerShell
  • Find Location and County by IP Address with PowerShell
  • Microsoft 365
  • Azure AD
  • SharePoint Online
  • Exchange Online
  • Microsoft Teams
  • Microsoft 365 Groups
  • OneDrive for Business
  • Azure AD Authentication
  • Active Directory
  • Exchange Server
  • PowerShell
  • PnP PowerShell
  • Microsoft Graph
  • CSOM
  • VBScript

Follow us

  • Facebook
  • Twitter
DMCA.com Protection Status

Tag » Active Directory Pwdlastset Convert To Date Powershell