title: PowerShell Get video duration and list all files recursively, export to csv
body: <p>I want to get a csv listing of all the video files (MTS or MP4 format) in a folder and its subfolders. I need the name with path, file size, and video duration.</p>
  
  <p>I had used this PowerShell script to successfully get a list of all the files from the main folder and subfolders. But this script does not get the video file metadata from which I can extract the duration.</p>
  
  <pre><code>Get-ChildItem  D:\'My Source Folder' -Recurse | where {!$_.PSIsContainer} | select-object FullName, LastWriteTime, Length | export-csv -notypeinformation -path C:\results_file.csv | % {$_.Replace('"','')}
  </code></pre>
  
  <p>I'm completely new to PowerShell scripting, so I'm unable to figure out how to get the videofile metadata.</p>
  
  <p>Note: I'm aware select-object * gets all the attributes of the file, but unfortunately that too does not have the duration which is specific to video files only.</p>
  
  <p>I also found <a href="https://stackoverflow.com/questions/25403621/recursively-list-video-duration-for-all-files-in-a-directory">this answer</a>, but I need a listing of all files in all subfolders, exported to a csv.</p>