top of page
Writer's pictureRattandeep singh

Mastering PowerShell: Effortlessly Transforming Date Formats!





133336113332972411 == 12 July 2023 10:25:33 AM



In today's blog I want to share my expirience with you all regarding handelling date and time in Active Directory. When I started working as an AD administrator I used dslookup commands and now we have PowerShell commands. However, there is one consfusion still the same, the time stamps.


There are certain attributes in AD to show the dates but that we can't understand untill we convert it in readable format.


What are those?

  • lastLogon

  • lastLogonTimestamp

  • pwdLastSet


What is the value/data type?

The Active Directory stores date/time values as the number of 100-nanosecond intervals that have elapsed since the 0 hour on January 1, 1601. It is called as FileTime.

A Windows file time is expressed in ticks.


You can see the example as follows:

133336113332972411 = 12 July 2023 04:55:33 AM -- UTC

133336113332972411 = 12 July 2023 10:25:33 AM -- IST


How to manage those time stamps?

I can simply share the PowerShell commands to convert. But, there is no fun in it.


So, let run some commands to understand, what we are discussing here?









I ran a simple command Get-Date to get the current date time and stored in a variable.

Now, let's convert this to the FileTime







How to convert this back to readable form?

Now, let's store this in a variable and covert with some more commands.











Now the time is back, I can read easily.


Note: The method FromFileTime() will convert the time in the selected time zone for the host. However, I can use another method FromFileTimeUTC() to convert the time in UTC format. Now the time below is different.









Yes this blog is over.


Don't worry I will write another one to show you the commands to convert the attributes.

  • lastLogon

  • lastLogonTimestamp

  • pwdLastSet


To be continued...



58 views1 comment

1 Comment


Rajbir Kaur
Rajbir Kaur
Jul 12, 2023

Very useful information. Thanks!

Like
bottom of page