I'm trying to get this script to do a subdirectory compare based on filename and then only files that are 30 days or younger. The Syntax seems to acceptable but the HandbrakeCLI encoding doesn't launch.
Clear screen
$SourceDir = "\\netshare\testing\Source\*.MP4"
$DestinationDir = "\\netshare\testing\Completed_mp4\*.MP4"
$s1 = get-childitem -path $SourceDir -Recurse -Force | Where-Object {$_.LastWriteTime -gt (Get-Date).addDays(-30)}
$d1 = get-childitem -path $DestinationDir -Recurse
$results = @(compare-object $s1 $d1) | Where-Object {$_.Name -ne $_.Name}
$quantity = $results | measure
$Filecount = $quantity
$Process = 0;
foreach ($result in $results){
Write-Host -----------------------------------------------------------------
Write-Host Handbrake Batch Encoding
$Process++;
$results = $file.DirectoryName + "\" + $file.BaseName + ".MP4";
$progress = ($Process / $filecount) * 100
$progress = [Math]::Round($progress,2)
#Clear-Host
Write-Host "Processing - $results"
Write-Host "File $Process of $Filecount - $progress%"
Write-Host -------------------------------------------------------------------------------
$s1 = get-childitem -path $SourceDir -Recurse -Force | Where-Object {$_.LastWriteTime -gt (Get-Date).addDays(-30)}
$d1 = get-childitem -path $DestinationDir -Recurse
Start-Process "C:\Users\Downloads\HandBrakeCLI-1.0.1-win-x86_64.exe -ArgumentList -q 25 -i '$results' -o '$d1'"
}
$results = @(compare-object $s1 $d1) | Where-Object {$_.Name -ne $_.Name}
would be a good start to look. This will not return any results unless $_.Name
is NaN
(which is unlikely).
Once you fixed that there should be an error message that
C:\Users\Downloads\HandBrakeCLI-1.0.1-win-x86_64.exe -ArgumentList -q 25 -i '$results' -o '$d1'
cannot be run.
Note that you use quotation marks around the whole line, effectively telling Start-Process
that the whole thing is the program to run. Which it isn't.
There's no need for Start-Process
here anyway, though, you should be able to just use
C:\Users\Downloads\HandBrakeCLI-1.0.1-win-x86_64.exe -q 25 -i $results -o $d1
(Note also that due to your use of single quotes, you were passing $results
and $d1
verbatim to the program instead of the variable contents. Furthermore I'm fairly sure you'd need commas between arguments with -ArgumentList
instead of spaces, as that would be normal PowerShell parameter binding behaviour.)
There are a bunch of other mistakes here:
Clear screen
can just be clear
, cls
, or Clear-Host
. The screen
does nothing.$quantity = $results | measure
should probably be $quantity = ($results | measure).Count
or simply @($results).Count
. Otherwise you won't get the output you want a few lines later.