Home > Mobile >  update object System.Printing.PrintQueue
update object System.Printing.PrintQueue

Time:06-01

I need to update an attribute in a printer driver. I'm able to get the right information but i don't know how to change this value.

Add-Type -AssemblyName System.Printing

$adminServer = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$adminPrinter = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter

$server = new-object System.Printing.LocalPrintServer $adminServer

$queues = $server.GetPrintQueues()

foreach($q in $queues){
$objPrinter = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,$adminPrinter
$objPrinter.CurrentJobSettings.CurrentPrintTicket.PageMediaType
}

The output of $objPrinter.CurrentJobSettings.CurrentPrintTicket.PageMediaType is Unknown and should be changed to AutoSelect

Can someone help me? :)

CodePudding user response:

It's been a while since I worked with Printer Management on Windows, but I'm fairly certain you want to update the DefaultPrintTicket rather than whatever settings are associated with the current job, so set it like this instead:

$objPrinter.DefaultPrintTicket.PageMediaType = 'AutoSelect'

... and then persist the configuration changes in the print server with PrintQueue.Commit():

$objPrinter.Commit()
  • Related