changing printer setting

Welcome Forums General PowerShell Q&A changing printer setting

This topic contains 3 replies, has 2 voices, and was last updated by

 
Moderator
1 year, 6 months ago.

  • Author
    Posts
  • #70363

    Participant
    Points: 0
    Rank: Member

    Hi. I need a little help here. We have a few old print servers and they want "keep printed jobs" turned on on all printers. The print servers are Server 2008. So printer management module is not available to me.

    I can see the property if i run

    get-wmiobject -class win32_printer -property keepprintedjobs

    However i can not figure out how to change this property. Everything i have tried has failed. I found VBScripts that can do this but i am determined to find the powershell way to do this.

    Also odd is is see "keepprintedjobs" as a property. But if put the above get-wmiobject into a variable (lets say $A)....and i then try to run
    $A.keepprintedjobs it yells that it is not a property that it can find. Can someone point me in the right direction.

    thank you

  • #70364

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Try the following, please:

    Get-WmiObject -Class Win32_Printer | Foreach-Object {
      $PSItem.KeepPrintedJobs = $true
      $PSItem.Put()
    }
    

    Let me know if it works.

    A bit more of an explanation. Your call of Get-WmiObject most likely returned an array of printer objects instead of just one. You'll need to loop over the array for example with Foreach-Object and update each object individually. However, just updating KeepPrintedJobs to True of each object won't change the printer queue configuration that is why you need to write it back to the printer server service with the Put() method.

    -Daniel

  • #70369

    Participant
    Points: 0
    Rank: Member

    excellent. that did work. thank you very much. I need to find some information on this Put() method as i have never used it before.

  • #70396

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Yeah. That is a bit of PowerShell magic in regards to WMI. You can see the method with

    $p = Get-WmiObject -Class Win32_Printer | Select-Object -First 1
    $p.psbase | Get-Member -MemberType Method
    

    MSDN documentation:
    https://msdn.microsoft.com/en-us/library/w09tfy94(v=vs.110).aspx

The topic ‘changing printer setting’ is closed to new replies.