PowerShell

Convert to and from Windows and Unix timestamps with PowerShell

Updated 8 Jan 2025: Module updated to v 1.0.2 and resigned. Links: GitHub, PowerShell Gallery

In this post I detail a module I’ve just published that is another of those I’ve done this before, but how do I find it again moments. Converting from Windows and Unix timestamps with PowerShell. A number of the PowerShell Modules I’ve published do contain the Unix timestamp conversion, but I couldn’t find Windows timestamp conversion as a function that I know I’ve previously written.

Therefore, in this post I detail the functions in the ConvertTime PowerShell module I’ve just published which allows you to convert to and from a PowerShell DateTime object and Unix & Windows timestamps. But what are Windows and Unix timestamps?

Windows Timestamps

A Windows timestamp is an 18-digit integer often referred to as an Active Directory timestamp, and more historically Windows32 FILETIME or SYSTEMTIME. In PowerShell it is also referenced as FileTime. In Active Directory it is the value used for attributes such as pwdLastSet, accountExpires, LastLogon, LastLogonTimestamp, and LastPwdSet. The 18-digit timestamp is the number of 100-nanosecond intervals (one billionth of a second) since Jan 1, 1601 UTC (Windows epoch).

example 132947402891099830

Unix Timestamps

The Unix timestamp is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT – Unix epoch), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Often these values are seen in APIs for lastUpdatedTime or similar.

example 1592001868

The Module

The module has been tested in Windows PowerShell (5.1) and PowerShell (7.x) on Windows.

The module contains four cmdlets (two with optional switches to return conversion result as UTC time) are:

  • Convert-UnixTime
  • Convert-WindowsTime
  • Get-UnixTime
  • Get-WindowsTime

Installing the module

Install direct from the PowerShell Gallery (Powershell 5.x and above)

install-module -name ConvertTime

Convert-UnixTime

Convert from Unix timestamp to a PowerShell DateTime Object relative to local time based of system time zone.

(optional) Return DateTime as Coordinated Universal Time

Convert-UnixTime 1592001868
Convert-UnixTime 1592001868 -UTC

Convert-WindowsTime

Convert from WindowsTime to PowerShell DateTime.

(optional) Return DateTime as Coordinated Universal Time

Convert-WindowsTime 132947402891099830
Convert-WindowsTime 132947402891099830 -UTC

Get-UnixTime

Convert PowerShell DateTime to Unix timestamp

Get-Date | Get-UnixTime
Get-Unixtime -datetime 'Sunday, 9 October 2022 2:47:48 PM'

Get-WindowsTime

Convert PowerShell DateTime to Windows timestamp

Get-Date | Get-WindowsTime
Get-WindowsTime -datetime 'Sunday, 9 October 2022 2:47:48 PM'

Summary

A versatile PowerShell Module for generating or converting Unix and Windows timestamps to and from PowerShell DateTime objects.

Darren Robinson

Bespoke learnings from a Microsoft Identity and Access Management Architect using lots of Microsoft Identity Manager, Azure Active Directory, PowerShell, SailPoint IdentityNow and Lithnet products and services.

Recent Posts

PowerShell MCP Azure Function Server

Recently under the experimental Azure Functions build Microsoft Developer Advocates have shown enabling Azure Functions…

2 days ago

EntraPulse – Your AI-Powered Gateway to Microsoft Graph & Docs

Today, I’m super excited to finally announce the Beta release of EntraPulse Lite – a…

2 months ago

Lokka MCP Authentication Enhancements

I'm excited to share some significant authentication enhancements I've contributed to the Lokka MCP Server…

3 months ago

AI Inception: Building AI Solutions with AI for AI

Last month I had the pleasure of speaking at the Sydney event for Global Azure.…

3 months ago

A Have I Been Pwned MCP Server for Claude

Model Context Protocol (MCP) is a powerful framework that extends AI clients like Claude and…

6 months ago

Azure AI Developer Hackathon

I've just completed participating in the Azure AI Developer Hackathon that was looking to provide…

6 months ago

This website uses cookies.