Recently, I was conducting some investigative work around mail delivery for a client. PowerShell cmdlets for Exchange are awesome and give us as administrators some real power in trying to figure out what is wrong. Some things in PowerShell though don’t take into account the regional language settings of the machine you’re working on. One example of this that left me scratching my head a little was when I was running Get-MessageTackingLog. Being in Australia we do our date as dd/mm/yyyy so I had the following command ready to run
Get-MessageTrackingLog -Server SRV-MBX-02 -Start "14/08/2014 08:00:00" -End "14/08/2014 15:00:00" -Sender "[email protected]" | ConvertTo-Html > "C:\Scripts\MsgTrack.html"
When I ran this I got an error around trying to convert a DateTime, I was sure I had entered the right format (also trying – and .)
Cannot process argument transformation on parameter 'Start'. Cannot convert value "14/08/2014 08:00:00" to type "System .DateTime". Error: "String was not recognized as a valid DateTime. + CategoryInfo : InvalidData: (:) [Get-MessageTrackingLog], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MessageTrackingLog
After a few minutes, I worked out the date needed to be in US Date/Time format of mm/dd/yyy. Swaping around my month and day got the command to work correctly and pipe out what I was after to a html page.
Interestingly, if you copy and paste a command out of the Tracking Log explorer the date and time format in there is based on the regional settings of the computer you are on, but run them through the Exchange Management Shell and you’ll also receive the above date/time error.