title: File date metadata not displaying properly
body: <p>I have been trying to write a Powershell script based on some <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2008/08/13/how-can-i-find-files-metadata.aspx" rel="nofollow">code online</a> that will read the metadata info from picture, video and other files and then sort them based on one of the dates (date taken currently seems to be the best bet if it's available, but date modified works on files that have not yet been altered).</p>
  
  <p>However, when I run the script and pull the info, I can't convert the string to a date. Here's roughly how I get the info through a COM object:</p>
  
  <pre><code>PS C:/&gt; $objShell = New-Object -ComObject Shell.Application
  PS C:/&gt; $objFolder = $objShell.namespace("C:\MyFolder")
  PS C:/&gt; $date = $objFolder.GetDetailsOf($objFolder.Items().Item(0), 12)
  PS C:/&gt; $date
  
  7/‎10/‎2014 ‏‎7:09 PM
  </code></pre>
  
  <p>The problem is I should be able to convert this to a datetime object. For instance, if I manually write it in it works:</p>
  
  <pre><code>PS C:/&gt; [datetime]::ParseExact("7/10/2014 7:09 PM","g",$null)
  
  Thursday, July 10, 2014 7:09:00 PM
  </code></pre>
  
  <p>But if I substitute the variable it doesn't work:</p>
  
  <pre><code>PS C:/&gt; [datetime]::ParseExact($date,"g",$null)
  Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
  At line:1 char:1
  + [datetime]::ParseExact($date,"g",$null)
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : FormatException
  </code></pre>
  
  <p>This is most likely due to the fact that the variable isn't actually what I'm seeing. It's in fact longer. Not to mention the fact that if you iterate through all the characters, you can see where the extra length is coming from:</p>
  
  <pre><code>PS C:\&gt; $date.Length #should be about 16, you'd think
  
  22
  
  PS C:\&gt; $datearray = @()
  PS C:\&gt; for ($i = 0; $i -lt $date.Length; $i++) {$datearray += $date[$i]}
  PS C:\&gt; $datearray #i'm printing on one line and in quotes for ease of viewing
  
  " 7/ 10/ 2014   7:09 PM"
  </code></pre>
  
  <p>If you try printing the array with a join or something similar, the results are (to me, without knowing what's going on) unpredictable. It treats it like it has 22 characters, but prints ignoring the spaces. </p>
  
  <p>I'm sure I could spend a bit of time and do some string formatting, but I'd rather just be able to parse the given date. What's going on?</p>
  
  <p>Edit: I'm able to access the file info easily, though I prefer not to. I'm mainly focusing on why the results I'm seeing are inconstant and showing a length that doesn't match how it prints out, and how I can deal with them. If nothing else, I'm curious as to what is going on.</p>