How to print multiple pdf files in a folder?
How to send pdf printing to a selected or specified printer other than the default printer?
PowerShell code snippet below will print all pdf files on a specified path or folder.
Change the variable or specify the printer in which the PDF files will be printed.
The script will get first whatever is the default printer and save the printer name to a variable.
After printing, you can either set the previous default printer. Or set a new printer default. You can also set any specific printer of your choice.
This script works fine in Windows 10.
#===================================
#Get the default printer and save to a variable
$DefPrinter=Get-WmiObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true"
Write-Output $DefPrinter
#List all printers if you don't know the printer name
$xgetPrinters=Get-WmiObject -Query " SELECT * FROM Win32_Printer" | Select Name
Write-Output $xgetPrinters
#Set the default printer for printing while the code is executed
$Printer_net = New-Object -COM WScript.Network
$Printer_net.SetDefaultPrinter("Adobe PDF")
$xpath="d:\ss\"
$folders=get-childitem $xpath | select Name
foreach($pdf_files in $folders)
{
$PDF_file_name = $pdf_files.Name;
Start-Process $xpath$PDF_file_name -Verb Print
}
#Put back to whatever default printer
#if there is a need to set the default printer to another printer
$Printer_net = New-Object -COM WScript.Network
#Specify a new printer
$Printer_net.SetDefaultPrinter("Microsoft Print to PDF")
#Or put back the default or old printer
$Printer_net.SetDefaultPrinter($DefPrinter)
#do an invoke-command to kill the adobe process
#===================================
Kill multiple processes using Powershell:
http://quickbytesstuff.blogspot.sg/2014/11/powershell-kill-multiple-processes.html
Cheers..Till next time. Enjoy scripting.
Comments
Post a Comment