Jessica Saxon
Jessica Saxon

Reputation: 91

Change printer paper tray settings via powershell

I attempted to use the WMI-Object to change the paper tray settings in powershell. However I've just learned that the value i'm trying to change is read-only apprently. Could someone help me accomplish task via powershell or VBScript?

$printers = Get-WMIObject -Class Win32_PrinterConfiguration | Where-Object {$_.Name -EQ "CHK.Checks"}
$printers.MediaType = 270
$printers.Put()

I attempted this and it did not work.

Please help!

Thanks in advance!

Upvotes: 1

Views: 7303

Answers (1)

BenH
BenH

Reputation: 10044

Since the value is read-only you won't be able to use WMI to set that. .Net has the System.Printing has an input bin setting, which isn't perfect but works. I've made a function around this in my PSPrintTools module. I think Tray1, Tray2 work as values as well, but I don't remember off the top of my head. Outside of this then you get into editing the PrintTicket XML. Here's the relevant code for just that feature:

$Printer = "Example Printer Name"
$InputBin = "AutoSelect","AutoSheetFeeder","Cassette","Manual","Tractor" #choose one
Add-Type -AssemblyName System.Printing
$Permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$QueuePerms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter
$PrintServer = new-object System.Printing.LocalPrintServer -ArgumentList $Permissions
$NewQueue = New-Object System.Printing.PrintQueue -ArgumentList $PrintServer,$Printer,1,$QueuePerms
$InputBinCaps = $NewQueue.GetPrintCapabilities().InputBinCapability
if ($null -ne $InputBinCaps) {
    if ($InputBinCaps.Contains([System.Printing.InputBin]::$InputBin)) {
        $NewQueue.DefaultPrintTicket.InputBin = [System.Printing.InputBin]::$InputBin
        $NewQueue.UserPrintTicket.InputBin = [System.Printing.InputBin]::$InputBin
    } else {
        Write-Error "$InputBin unavailable on $Printer"
    }
}
$NewQueue.commit()
$NewQueue.dispose()
$PrintServer.commit()
$PrintServer.dispose()

Upvotes: 2

Related Questions