Your task requires several steps
- List documents, use a RegEx to split name from revision,
- group the documents by name,
- per group sort by revision numerically,
- get only the highest rev. (last one)
- select a printer / or use a defined one / default standard printer
Since your revision numbers have a diverging count of places you need to sort numerical,
this is realized with $ToNatural
To test the sorting I used an extended sample (revisions to print are marked **)
44-0-19.pdf
44-0-190.pdf
44-0-191.pdf **
44-0-2.pdf
630-0-110.pdf **
630-0-90.pdf
9A-0-10.pdf **
9A-0-9.pdf
## Q:\Test\2018\07\09\SO_51246286.ps1
#Requires -Version 3
## To sort numbers with a different places count use:
## $ToNatural from Roman Kuzmin source https://stackoverflow.com/a/5429048/6811411
$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20,"0") }) }
Push-Location "X:\start\folder"
$PDFsToPrint = (Get-ChildItem *.pdf -File |
Where-Object BaseName -match '^([0-9]+[A-C]?-\d+)-(\d+)$'|
Group-Object {$Matches[1]} |
Foreach-Object {
$_.Group | Sort-Object $ToNatural | Select-Object -Last 1
} ).FullName
# $PDFsToPrint
Pop-Location
$Printer = Get-Printer | Select-Object Name,Drivername,PortName |
Out-GridView -Title "Select the printer for output" -OutputMode Single
#Adobe SDK: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf
$Acrobat = 'C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe'
ForEach($Pdf in $PDFsToPrint) {
$ArgList=' /S /T "{0}" "{1}" "{2}" {3}' -f `
$Pdf,
$Printer.Name,
$Printer.DriverName,
$Printer.PortName
Start-Process $Acrobat -ArgumentList $ArgList
#Start-Sleep -Seconds 60 #optional delay
}