FileTimes are kept in 64-bit integers. They don't have any time zone information. I think what you want to do is to use the FromFileTimeUtc method and avoid the conversion to local time.
Get-ADUser datetime time zone
Brian Wilson
21
Reputation points
When trying to pull AD user account info using the below script I get different date/time stamps depending on the time zone of the server pulling the results. Is there a way to set the time zone as a variable in the script to make the results accurate, as defined to the time zone, regardless of the time zone of the server pulling the results.
$ExportPath = 'users_in_ou.csv'
Get-ADUser -Properties * -Filter * | Select `
CN, @{Name='lastLogon'; Expression={if($_.lastLogon -ne $null -and $_.lastLogon -gt '0'){[datetime]::FromFileTime($_."lastLogon")}else{''}}} `
, @{Name='lockoutTime'; Expression={if($_.lockoutTime -ne $null -and $_.lockoutTime -gt '0'){[datetime]::FromFileTime($_."lockoutTime")}else{''}}} `
| export-csv $ExportPath -NoTypeInformation
Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Development | Other
Building custom solutions that extend, automate, and integrate Microsoft 365 apps.