How can I use PowerShell on Windows to get the current time in the Windows FILETIME format?
Something like this answer about Linux except for Windows, using the Windows FILETIME format (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 UTC), and preferably something simple like the aforementioned answer.
Alternatives:
[dateime]::Now.ToFileTimeUtc()or[datetimeoffset]::Now.ToFileTime()To convert such a
FILETIMEvalue back to a[datetime]instance:Note: The above yields a local
[datetime]instance (its.Kindproperty isLocal). Append.ToUniversalTime()to get a UTC instance (where.KindisUtc).Or, use
[datetime]::FromFileTimeUtc()(note theUtcsuffix), which directly yields a UTC[datetime]instance:Alternatively, use
[datetimeoffset]::FromFileTime()to obtain an unambiguous timestamp, which can be used as-is or converted to a local (.LocalDateTime) or a UTC (.UtcDateTime)[datetime]instance, as needed.