title: Cannot convert 'System.Object[]' to 'System.DateTime'
body: <p>I'm attempting to write a script that will compare the dates of two versions of the same file, and copy it across if appropriate. </p>
  
  <p>Being new to Powershell, I am just attempting to figure out the correct syntax to get this working, however I've run into a glitch, and I'm not sure what is happening or why.</p>
  
  <pre><code>$RemotePath = "e:\to be copied"
  $LocalPath = "C:\temp"
  $Curr_date = get-date
  
  #Checking date and then copying file from RemotePath to LocalPath
  Foreach($file in (Get-ChildItem $RemotePath))
  {
      #Check if file exists. If it doesn't, copy the file.
      if (-Not (Test-Path "$LocalPath\$file"))
      {
          echo "$LocalPath\$file"
          "$file does not exist"
      }
      else
      {
          $LocalFile = (Get-ChildItem $LocalPath)
          echo $LocalFile
          echo $LocalFile.LastWriteTime
          echo $file
          echo $file.LastWriteTime
          #Check if newer (greater) than date of file in the Local Path
          if((get-date $file.LastWriteTime) -gt (get-date $LocalFile.LastWriteTime))
          {
              echo $Curr_date
              echo $file.LastWriteTime
              echo $LocalFile.LastWriteTime
          }
          #If not newer, don't copy file.
          else
          {
              echo $Curr_date
              echo $file.LastWriteTime
              echo $LocalFile.LastWriteTime
              "not copying $file"
          }
      }
  }
  </code></pre>
  
  <p>I <em>believe</em> it's caused by the line:</p>
  
  <pre><code>if((get-date $file.LastWriteTime) -gt (get-date $LocalFile.LastWriteTime))
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <pre><code>Get-Date : Cannot convert 'System.Object[]' to the type 'System.DateTime' required by parameter 'Date'. Specified method is not supported.
  At C:\Users\Benjamin\Desktop\PowerShell.ps1:24 char:57
  +         if((get-date $file.LastWriteTime) -gt (get-date $LocalFile.LastWriteTime ...
  +                                                         ~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
      + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetDateCommand
  </code></pre>
  
  <p>Additionally, this echo's the data for the files in <code>C:\temp</code>, then one file in <code>E:\To be copied</code>, then throws the error. It then loops again, echo's the files in <code>C:\temp</code>, then the <em>other</em> file in <code>E:\To be copied</code>, then throws the error again.</p>