Skip to content

Instantly share code, notes, and snippets.

@jaredhaight
Last active May 9, 2019 01:04
Show Gist options
  • Save jaredhaight/c8d3c6f71c8687cea5bc9485eddd7588 to your computer and use it in GitHub Desktop.
Save jaredhaight/c8d3c6f71c8687cea5bc9485eddd7588 to your computer and use it in GitHub Desktop.
Get Total Length of Time from a Directory of Videos
# Stolen from here: https://social.technet.microsoft.com/Forums/en-US/bad2dbb1-5deb-48b8-8f8c-45e2b353dba0/how-do-i-get-video-file-duration-in-powershell-script?forum=winserverpowershell#de6ee12a-1c1e-474f-b5ba-ece4b17e0144
function Get-VideoLength {
param (
$Path
)
if (-not $Path) {
$Path = (Get-Location).Path
}
$videos = Get-ChildItem $Path
$objShell = New-Object -ComObject Shell.Application
$folder = $objShell.NameSpace($Path)
[timespan]$TotalTime = '00:00:00'
forEach ($video in $videos) {
$objFile = $folder.ParseName($video.Name)
$TotalTime += [timespan]$folder.GetDetailsOf($objFile, 27)
}
$TotalTime | Select-Object Days, Hours, Minutes, Seconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment