#powershell Get-Date v.s. [datetime] Format and System Locale

When a datetime attribute, say whenChanged in Active Directory gets dump to a text file via Export-Csv, the actual object type stored is that of a string. The format saved is dependent on the system locale. Typically for non en-us western locales, the day precedes the month instead of vice versa.

To convert this back to the proper datetime format through Import-Csv, use…… Get-Date instead of the .NET [datetime] adapter class. This is because the latter appears to be hard-coded to work with en-us locale contrary to the real settings exposed in $host.CurrentCulture.DateTimeForm.

Leave a Reply