param ($ChangeProp)
$host.Runspace.ThreadOptions = "ReuseThread" Add-Type -AssemblyName System.Printing $permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer $queueperms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter $server = new-object System.Printing.PrintServer -argumentList $permissions $queues = $server.GetPrintQueues()
function SetProp($capability, $property, $enumeration) { if ($PrintCaps.$capability.Contains($property)) { $q2.DefaultPrintTicket.$enumeration = $property $q2.commit() write-host ($q.Name +" is now configured for " + $property) } else { write-host ($q.Name +" does not support " + $property) } } try { foreach ($q in $queues) { #Get edit Permissions on the Queue $q2 = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,1,$queueperms # Get Capabilities Object for the Print Queue $PrintCaps = $q2.GetPrintCapabilities() switch ($ChangeProp) { {$_ -eq "twosided"} { SetProp DuplexingCapability TwoSidedLongEdge Duplexing break } {$_ -eq "onesided"} { SetProp DuplexingCapability onesided Duplexing break } {$_ -eq "mono"} { SetProp OutputColorCapability monochrome OutputColor break } {$_ -eq "color"} { SetProp OutputColorCapability color OutputColor break } {$_ -eq "staple"} { SetProp StaplingCapability StapleTopLeft Stapling break } default { Write-Host ("$_ is not a valid parameter") exit } } } } catch [System.Management.Automation.RuntimeException] { write-host ("Exception: " + $_.Exception.GetType().FullName) write-host $_.Exception.Message } Here is an update which adds a "show" parameter to show the properties of the print queues:
$host.Runspace.ThreadOptions = "ReuseThread" Add-Type -AssemblyName System.Printing
$permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer $queueperms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter $server = new-object System.Printing.PrintServer -argumentList $permissions $queues = $server.GetPrintQueues()
function SetProp($capability, $property, $enumeration) { if ($PrintCaps.$capability.Contains($property)) { $q2.DefaultPrintTicket.$enumeration = $property $q2.commit() write-host ($q.Name +" is now configured for " + $property) write-host (" ") } else { write-host ($q.Name +" does not support " + $property) write-host (" ") } } try { foreach ($q in $queues) { #Get edit Permissions on the Queue $q2 = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,1,$queueperms # Get Capabilities Object for the Print Queue $PrintCaps = $q2.GetPrintCapabilities() switch ($ChangeProp) { {$_ -eq "twosided"} { SetProp DuplexingCapability TwoSidedLongEdge Duplexing break } {$_ -eq "onesided"} { SetProp DuplexingCapability onesided Duplexing break } {$_ -eq "mono"} { SetProp OutputColorCapability monochrome OutputColor break } {$_ -eq "color"} { SetProp OutputColorCapability color OutputColor break } {$_ -eq "staple"} { SetProp StaplingCapability StapleTopLeft Stapling break } {$_ -eq "show"} { $DefaultTicket = $q2.DefaultPrintTicket $TicketProps = $DefaultTicket | Get-Member -MemberType Property write-host (" ") write-host ($q.name) foreach ($p in $TicketProps) { $PName = $p.name $PropValue = $DefaultTicket.$PName write-host ($p.name + " = " + $PropValue) } } default { Write-Host ("$_ is not a valid parameter") exit } } } } catch [System.Management.Automation.RuntimeException] { write-host ("Exception: " + $_.Exception.GetType().FullName) write-host $_.Exception.Message }
Great and innovative use of TechNet Wiki! Is there a PowerShell Script Gallery (on MSDN) that you can post to as well? Thanks!
The Script Center also allows you to post in 'code' format so it is easier to read. I think it also had a much wider audience to assist you with the script.
Hi,
first of all, i would like to thank you for this script :D
But i would like to know how it is possible to modify it in order to configure printers networkingly connected (with a windows share).
I wanted to use it to force my users to have mono printers.
Thanks a lot ^^