0

Im a little confused by this. If I use the Get-printer command I get the printers list. So I know the printer is there.

Get-Printer

Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType     
----                           ------------    ----         ----------                --------        ------   ---------  ----------     
OneNote (Desktop)                              Local        Send to Microsoft OneN... nul:            False    False      Print          
UNBILLING                                      Local        Ghostscript PDF           unbilling       False    False      Print          
tiquete                                        Local        Generic / Text Only       com.printdis... False    False      Print          
OneNote for Windows 10                         Local        Microsoft Software Pri... Microsoft.Of... False    False      Print          
Microsoft XPS Document Writer                  Local        Microsoft XPS Document... PORTPROMPT:     False    False      Print          
Microsoft Print to PDF                         Local        Microsoft Print To PDF    PORTPROMPT:     False    False      Print          
Fax                                            Local        Microsoft Shared Fax D... SHRFAX:         False    False      Print          
EXPORT                                         Local        Generic / Text Only       C:\Users\Jua... False    False      Print          
EPSON TM-U220 Receipt                          Local        EPSON TM-U220 ReceiptE4   ESDPRT001       False    False      Print          
Adobe PDF                                      Local        Adobe PDF Converter       Documents\*.pdf False    False      Print    

But I make the command.

start-process -filepath "$root\UNB\FINAL_TEXTO\$archivo" -verb print | out-printer -Name "UNBILLING"  

The print job will not be sent if the printer is not set as DEFAULT. I don't want that, I want to send it to the specific printer not matter if its default or not.

Any help is appreciated.

  • The cmdlet out-printer is writing raw data to the printer with no formatting. The printer you are using wants to see PDF data and if not PDF will not print. See following to convert text to pdf : https://stackoverflow.com/questions/23892631/convert-text-file-to-pdf-file-using-powershell – jdweng Dec 11 '22 at 02:40
  • That's not the case the printer prints fine as long as it is the default printer. If it's not, even if I command to print it in that particular printer it won't do it – Juan Manuel Sanchez Dec 11 '22 at 03:05

1 Answers1

1

You need to first find the printer currently set as Default in order to change that (temporarily) to the printer you want to be used.

For that you can use CIM:

# get a list of printer objects and select the current Default and the 'UNBILLING' printers
$allPrinters    = Get-CimInstance -ClassName Win32_Printer
$defaultPrinter = $allPrinters | Where-Object { $_.Default -eq $true }
$printerToUse   = $allPrinters | Where-Object { $_.Name -eq 'UNBILLING' }

# temporarily set your printer as Default
$null = Invoke-CimMethod -InputObject $printerToUse -MethodName SetDefaultPrinter

# now start the application for thw $archivo filetype and invoke its 'Print' verb
Start-Process -FilePath "$root\UNB\FINAL_TEXTO\$archivo" -Verb print

# after printing, restore the previous default printer
$null = Invoke-CimMethod -InputObject $defaultPrinter -MethodName SetDefaultPrinter
Theo
  • 57,719
  • 8
  • 24
  • 41