Convert string yyyy-MM-dd'T'HH:mm:ss'Z to date


I’m using Get-AzureADAuditSignInLogs cmdlet from the Azure AD Public Preview module to audit last sign in times for users.

Like this:

$lastSignIn = get-AzureADAuditSignInLogs | select UserDisplayName,UserPrincipalName,CreatedDateTime

I’m particular interested in the CreatedDateTime property which is returned as a string in this format:

ame MemberType Definition

CreatedDateTime NoteProperty string CreatedDateTime=2020-04-07T16:55:35.439072Z

I eventually want to compare it against another date but in it’s current format will not be able to do it. I’m struggling to convert the string to a date format PowerShell recognises.

Any ideas?






Parses fine for me:

PS C:\WINDOWS\system32> [datetime]::Parse('2020-04-07T16:55:35.439072Z')

Tuesday, April 7, 2020 12:55:35 PM

PS C:\WINDOWS\system32> Get-Date -Date '2020-04-07T16:55:35.439072Z'

Tuesday, April 7, 2020 12:55:35 PM


$lastSignIn = get-AzureADAuditSignInLogs | 
              select UserDisplayName,

This works. Thanks a lot.