I'm trying to create some powershell to distribute video encoding to each of my computers in the house. So far I have done just that. I actually created a function that does great on a single localhost or to another computer just fine using ffmpeg for now. What I would like to do now is take each of these chunks of any array (the array is of my movie files) and have it be a work list for each computer. Since I am pretty new to programing in general I am trying to find a loop,while,foreach that works with this idea and I am stumbling with it. So far here is what I have.
Function Split-Every($List, $count) {
$aggregateList = @()
$blocks = [Math]::Floor($list.Count / $count)
$leftOver = $list.Count % $count
for($i=0; $i -lt $blocks; $i++) {
$end = $count * ($i + 1) - 1
$aggregateList += @(,$list[$start..$end])
$start = $end + 1
}
if($leftOver -gt 0) {
$aggregateList += @(,$list[$start..($end+$leftOver)])
}
$aggregateList
}
$Directories = '\\servername\Videofilder\'
$Dir = get-childitem $Directories -recurse
$extensions = @(".mkv", ".mp4", ".mov")
$FileSize = $Dir | Where-Object {$_.length/1MB -gt 500}
$List = $FileSize | where {$_.extension -in $extensions}
$VideoFileChuck = Split-Every -List $List -count 25
So what this now leaves me with is $VideoFileChunks[0] which has the first 25 movies, $VideoFileChunks[1] has the next 25 movies, etc... On a single computer I would then pipe
$VideoFileChunks[0] | % {& $FFMpeg -y -i $_.fullname -vcodec $vcodec -b:v $vbitrate -acodec $acodec \\servername\Videofilder\ConvertedVideo\ $($_.basename).mp4}
and it would convert the video (I have ffmpeg variables in the function as well and they work fine but will probably rethink that as I develop the idea more and want to add more tools)
Without manually assigning to each computer and running this manually:
Invoke-Command -ComputerName computer01 -ScriptBlock {
Function Split-Every($List, $count) {
$aggregateList = @()
$blocks = [Math]::Floor($list.Count / $count)
$leftOver = $list.Count % $count
for($i=0; $i -lt $blocks; $i++) {
$end = $count * ($i + 1) - 1
$aggregateList += @(,$list[$start..$end])
$start = $end + 1
}
if($leftOver -gt 0) {
$aggregateList += @(,$list[$start..($end+$leftOver)])
}
$aggregateList
}
$Directories = '\\servername\Videofilder\'
$Dir = get-childitem $Directories -recurse
$extensions = @(".mkv", ".mp4", ".mov")
$FileSize = $Dir | Where-Object {$_.length/1MB -gt 500}
$List = $FileSize | where {$_.extension -in $extensions}
$VideoFileChuck = Split-Every -List $List -count 25
$VideoFileChunks[0] | % {& $FFMpeg -y -i $_.fullname -vcodec $vcodec -b:v $vbitrate -acodec $acodec \\servername\Videofilder\ConvertedVideo\ $($_.basename).mp4}
}
I would like to send $VideoFileChunks[0] to something like $ComputerName[0] and loop through $VideoFileChunks[1..50] and each chunk goes to a new $ComputerName[1.25] so as to not need to manually assign and run a new powershell command manually with Invoke-Command -ComputerName computer01 -ScriptBlock {}
Sorry if I wasn't clear with this as I am not so great with programming concepts at this point. I appreciate any advice that can be given, I will attempt to read up on any concepts given to me since I don't expect anyone to write this for me, so I can "learn to fish vs being given a fish".
Function Split-Every($List, $count) {
$aggregateList = @()
$blocks = [Math]::Floor($list.Count / $count)
$leftOver = $list.Count % $count
for($i=0; $i -lt $blocks; $i++) {
$end = $count * ($i + 1) - 1
$aggregateList += @(,$list[$start..$end])
$start = $end + 1
}
if($leftOver -gt 0) {
$aggregateList += @(,$list[$start..($end+$leftOver)])
}
$aggregateList
}
$Directories = '\\servername\Videofilder\'
$Dir = get-childitem $Directories -recurse
$extensions = @(".mkv", ".mp4", ".mov")
$FileSize = $Dir | Where-Object {$_.length/1MB -gt 500}
$List = $FileSize | where {$_.extension -in $extensions}
$VideoFileChuck = Split-Every -List $List -count 25
So what this now leaves me with is $VideoFileChunks[0] which has the first 25 movies, $VideoFileChunks[1] has the next 25 movies, etc... On a single computer I would then pipe
$VideoFileChunks[0] | % {& $FFMpeg -y -i $_.fullname -vcodec $vcodec -b:v $vbitrate -acodec $acodec \\servername\Videofilder\ConvertedVideo\ $($_.basename).mp4}
and it would convert the video (I have ffmpeg variables in the function as well and they work fine but will probably rethink that as I develop the idea more and want to add more tools)
Without manually assigning to each computer and running this manually:
Invoke-Command -ComputerName computer01 -ScriptBlock {
Function Split-Every($List, $count) {
$aggregateList = @()
$blocks = [Math]::Floor($list.Count / $count)
$leftOver = $list.Count % $count
for($i=0; $i -lt $blocks; $i++) {
$end = $count * ($i + 1) - 1
$aggregateList += @(,$list[$start..$end])
$start = $end + 1
}
if($leftOver -gt 0) {
$aggregateList += @(,$list[$start..($end+$leftOver)])
}
$aggregateList
}
$Directories = '\\servername\Videofilder\'
$Dir = get-childitem $Directories -recurse
$extensions = @(".mkv", ".mp4", ".mov")
$FileSize = $Dir | Where-Object {$_.length/1MB -gt 500}
$List = $FileSize | where {$_.extension -in $extensions}
$VideoFileChuck = Split-Every -List $List -count 25
$VideoFileChunks[0] | % {& $FFMpeg -y -i $_.fullname -vcodec $vcodec -b:v $vbitrate -acodec $acodec \\servername\Videofilder\ConvertedVideo\ $($_.basename).mp4}
}
I would like to send $VideoFileChunks[0] to something like $ComputerName[0] and loop through $VideoFileChunks[1..50] and each chunk goes to a new $ComputerName[1.25] so as to not need to manually assign and run a new powershell command manually with Invoke-Command -ComputerName computer01 -ScriptBlock {}
Sorry if I wasn't clear with this as I am not so great with programming concepts at this point. I appreciate any advice that can be given, I will attempt to read up on any concepts given to me since I don't expect anyone to write this for me, so I can "learn to fish vs being given a fish".