I have a PowerShell script that simply converts any number of PSD files to PNG files.
Here's the code:
param (
[Parameter(Mandatory,Position = 0)]
[String]
$FileList,
[Parameter(Mandatory)]
[ValidateSet('png','jpg',IgnoreCase = $true)]
[String]
$DestFormat
)
$Files = Get-Content $FileList
$Files | ForEach-Object -Parallel {
$MagickArgs = [System.Collections.ArrayList]@()
$File = $_
$OrgFilePathOnly = [System.IO.Path]::GetDirectoryName($File)
$OrgFilenameNoExtension = [System.IO.Path]::GetFileNameWithoutExtension($File)
$OrgFilename = $OrgFilenameNoExtension + '.psd[0]'
$OrgFile = $OrgFilePathOnly + '\' + $OrgFilename
$NewFile = [System.IO.Path]::ChangeExtension($File, ($Using:DestFormat).ToLower())
magick.exe -monitor $OrgFile $NewFile | Out-Null
} -ThrottleLimit 20
Everything is working fine, but I want to be able to show a progress bar in the console window for each conversion. If I add the -monitor flag to the magick call, I get output like:
save image[D:\2D\Test\Just Flow Dark 03.png]: 50 of 4500, 01% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 100 of 4500, 02% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 150 of 4500, 03% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 200 of 4500, 04% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 250 of 4500, 05% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 300 of 4500, 06% complete
Etc. While I could probably just leave things like they are, I want to learn how to redirect or capture this output in such a way that I can display a custom progress bar (either winforms or Show-Progress / Write-Progress).
Any help at all would be great.
Thanks!