Advertisement
Kevinator

Get-ChildItem - Optimize?

Apr 14th, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Get Episodes
  2. Get-ChildItem $showDirectory -Recurse -File | Where-Object { $_.Extension -in (".mp4", ".mkv", ".avi", ".m4v", ".mpg") } | ForEach-Object {
  3.  
  4.     $insertQuery = @"
  5.    INSERT INTO Episodes VALUES ('$($_.Directory.Parent.Name -replace "'", "")',
  6.                                 '$($_.Directory.Name)',
  7.                                 '$($_.Name -replace "'", "")',
  8.                                '$($_.Length)',
  9.                                '$((ReadableFileSize $_.Length))',
  10.                                '$((VideoDurationSeconds $_.FullName))',
  11.                                '$((ReadableDuration $_.FullName))',
  12.                                '$((Get-VideoResolution $_.FullName))',
  13.                                '$($_.Extension)',
  14.                                '$($_.LastWriteTime)',
  15.                                '$($_.CreationTime)',
  16.                                GETDATE())
  17. "@
  18.     Invoke-Sqlcmd -ConnectionString $connectionString -Query $insertQuery -ErrorAction Stop
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement