none
Create and configure a shared printer in a GPO with powershell

    Question

  • Hello!How I can create and configure a shared printer in a GPO with powershell?

    I need to config:

    "Action"

    "Share Link"

    "Item lvl-targetting" with choosing policy group element

    use "Run in logged on users security context"

    Wednesday, May 30, 2018 12:43 PM

All replies

  • I know how to do it in a powershell login script (it may fail the first time or be slow depending on your situation):

    foreach ($printer in $printers) {
      add-printer -connectionname "\\$server\$printer"
      while (-not $?) { sleep 1;
        add-printer -connectionname "\\$server\$printer" }
    }



    Windows shared printers are kind of a nightmare of undocumented features since Server 2008.  I suggest checking out the Print/Fax Technet forum, and learning about the registry key "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\Client Side Rendering Print Provider", and the random port the Print Spooler service listens on.

    • Marked as answer by RSDNT Wednesday, May 30, 2018 1:14 PM
    • Unmarked as answer by RSDNT Wednesday, May 30, 2018 1:14 PM
    • Edited by JS2010 Thursday, May 31, 2018 2:53 PM
    Wednesday, May 30, 2018 1:04 PM
  • I found an interesting article, but it uses a commercial product. The functional that I need, but unfortunately as I understood it is paid in part. Maybe there are alternatives? 
    https://janegilring.wordpress.com/2010/01/18/automate-group-policy-preferences-printer-management-using-windows-powershell-2/

    Wednesday, May 30, 2018 1:20 PM
  • That article is too old.  The GPP extensions are now owned by Microsoft and are part of all current AD deployments.


    \_(ツ)_/

    Wednesday, May 30, 2018 2:50 PM
    Moderator
  • and how to be able to write a script to make settings?
    Wednesday, May 30, 2018 3:16 PM
  • Follow the instructions in the article.


    \_(ツ)_/

    Wednesday, May 30, 2018 3:26 PM
    Moderator
  • I can't find for download Module SDM-Group Policy on link from article...or something I misunderstood?
    Thursday, May 31, 2018 8:59 AM
  • The module is part of Windows and does not need to be downloaded.  You must install RSAT.


    \_(ツ)_/

    Thursday, May 31, 2018 2:02 PM
    Moderator
  • help *printer*

    But in my case everything is set on the server.  I set the default printer as the user like this (assuming Windows 10 isn't handling the default printer):

    $printerObject = Get-WmiObject win32_printer |
      where name -eq "\\$server\$defaultprinter"
    $printerObject.SetDefaultPrinter() > $null







    • Edited by JS2010 Thursday, May 31, 2018 3:16 PM
    Thursday, May 31, 2018 2:26 PM
  • everything did as in the article + installed RSAT, but when executing the command with my settings I get an error:

    Get-SDMgpobject : The term 'Get-SDMgpobject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
    name, or if a path was included, verify that the path is correct and try again

    Thursday, May 31, 2018 2:30 PM
  • The GPO sets the printers for the users included in the GPO. 

    Here is how to deploy printers with GPO. https://blogs.technet.microsoft.com/canitpro/2015/02/03/step-by-step-setting-up-printers-via-group-policy/


    \_(ツ)_/

    Thursday, May 31, 2018 2:33 PM
    Moderator
  • Here is the best way to install, maintain and assign printers.  It is the print management tool which has been included in Windows servers since WS2003R2.

    https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc753109(v=ws.10)

    It manages printers in the domain and all GPO settings from one console.


    \_(ツ)_/

    Thursday, May 31, 2018 2:37 PM
    Moderator
  • everything did as in the article + installed RSAT, but when executing the command with my settings I get an error:

    Get-SDMgpobject : The term 'Get-SDMgpobject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
    name, or if a path was included, verify that the path is correct and try again

    You have to use the GPO module to edit GPO policies.   There is no specific printer component.  You will have to learn GPO and the CmdLets. 

    Use the Print Management Application linked above as it will do all of this for you.  There is no need to use PowerShell.


    \_(ツ)_/

    Thursday, May 31, 2018 2:41 PM
    Moderator
  • Group policy should work fine, but I think it's easier to troubleshoot with powershell, and I've had to do a LOT of troubleshooting with windows shared printing.  Plus you can set everything once in one file and easily start over.


    • Edited by JS2010 Thursday, May 31, 2018 2:52 PM
    Thursday, May 31, 2018 2:48 PM
  • I know how to manually create a printer in the GP for automapping. But when you need to do this with 200+ printers, it turns into hell...Therefore, I try to solve the problem with a script, but really I can not find anything
    Thursday, May 31, 2018 3:12 PM
  • Example of how my coworker set the duplex on a printer on the server.

    Set-PrintConfiguration -printername $PrinterName -duplexingmode TwoSidedLongEdge


    Disable advanced features and bidirectional printing on a server printer using a vbscript utility.

    prncnfg.vbs -t -p $PrinterName +rawonly -enablebidi



    • Edited by JS2010 Thursday, May 31, 2018 3:30 PM
    Thursday, May 31, 2018 3:26 PM
  • Example of how my coworker set the duplex on a printer on the server.

    Set-PrintConfiguration -printername $PrinterName -duplexingmode TwoSidedLongEdge



    This has nothing to do with GPO assignment of printers.


    \_(ツ)_/

    Thursday, May 31, 2018 3:28 PM
    Moderator
  • I know how to manually create a printer in the GP for automapping. But when you need to do this with 200+ printers, it turns into hell...Therefore, I try to solve the problem with a script, but really I can not find anything

    Print Manager will let you select all printers by group, location, type and assign all to a group of users, a use or an OU.

    GPP printer assignment is not how printer deployment is done in modern windows.


    \_(ツ)_/

    Thursday, May 31, 2018 3:30 PM
    Moderator
  • That's news to me.  Where is that documented?

    Thursday, May 31, 2018 3:31 PM
  • That's news to me.  Where is that documented?

    I posted the link above.  You need to read the complete set of documents that describe installation of Print Management as well as how to configure print queues.

    In Windows we do not assign printers.  We assign queues.  A single printer can have many queues.  Queues can be configured differently to provide different printer behaviors.  Print Manager can assign a queue or multiple queues to users via the Printer Deployment GPO policies.  If you have more than a couple of print queues then you need print management.  There are many companies that sell print management solutions.  The Microsoft version included with Windows Server is the best place to start.  It can be easily upgraded to third party products when necessary.

    Most post we find on the net seem to only reflect old NT4 or W2K methods of printer management.  Windows has evolved tremendously since then.


    \_(ツ)_/

    Thursday, May 31, 2018 3:38 PM
    Moderator
  • I'm sure we've come a long way since Server 2003, except for the online documentation.  Your link has a typo.  That link still talks about using Group Policy.



    • Edited by JS2010 Thursday, May 31, 2018 3:46 PM
    Thursday, May 31, 2018 3:43 PM
  • To create a printer deployment GPO we would start with "New-GPO" and start it from astarter template that is based on the Printer deployment GPO.  From there it can be customized and assigned with GP CmdLets:

    See: https://docs.microsoft.com/en-us/powershell/module/grouppolicy/new-gpo?view=win10-ps

    Here are the GPO CmdLets: https://technet.microsoft.com/de-de/library/hh967461%28v=wps.630%29.aspx?f=255&MSPPError=-2147217396

    How you design the deployment would be up to you.  I recommend using Print Management and looking at how it creates the deployment GPOs.  In the end I am sure that you will choose to just use Print Management to do all of the work and skip using the CmdLets except to edit the generated GPOs if necessary.

    Here is a good introductory article on how to use the GPO CmdLets: http://www.powershellmagazine.com/2012/05/14/managing-group-policy-with-powershell/


    \_(ツ)_/

    Thursday, May 31, 2018 3:46 PM
    Moderator
  • I'm sure we've come a long way since Server 2003, except for the online documentation.  Your link has a typo.  That link still talks about using Group Policy.




    Au Contraire mon ami.  There are a huge amount of excellent documents online.

    \_(ツ)_/

    Thursday, May 31, 2018 3:49 PM
    Moderator
  • Excellent documents that tell you which ports the print spooler listens on?  Or how client-side rendering works when you regularly delete profiles?  I also don't think print management is good for automation.  This is how we create the printers on the server:

    pnputil.exe /add-driver .\hpcu210u.inf
    add-printerdriver -name "HP Universal Printing PCL 6"
    add-printerport -name hp1port -PrinterHostAddress hp1
    add-printer -name prin -drivername "HP Universal Printing PCL 6" -portname hp1port



    • Edited by JS2010 Thursday, May 31, 2018 4:10 PM
    Thursday, May 31, 2018 4:09 PM
  • Excellent documents that tell you which ports the print spooler listens on?  Or how client-side rendering works when you regularly delete profiles?  I also don't think print management is good for automation.  This is how we create the printers on the server:

    pnputil.exe /add-driver .\hpcu210u.inf
    add-printerdriver -name "HP Universal Printing PCL 6"
    add-printerport -name hp1port -PrinterHostAddress hp1
    add-printer -name prin -drivername "HP Universal Printing PCL 6" -portname hp1port



    Again.  The question is not about creating printers.  It is about deploying already created printers using  GP.  Not the same thing. "Deploying" means assigning a print spooler queue to a user or group.

    GP does this better that any old W95 or NT4 methods.  When set up correctly it assigns the queue and selects and intalls the correct driver.

    Your method is for non-domain printers and local printers.  It has nothing to do with GP printer deployment which we have used since WS2003R2.


    \_(ツ)_/


    Thursday, May 31, 2018 4:32 PM
    Moderator
  • These printers are created on a server, and then shared.  There might be a way to automate Print Management.  I'm not sure how straightforward it is.

    https://janegilring.wordpress.com/category/print-management/


    • Edited by JS2010 Thursday, May 31, 2018 5:00 PM
    Thursday, May 31, 2018 5:00 PM
  • These printers are created on a server, and then shared.  There might be a way to automate Print Management.  I'm not sure how straightforward it is.

    https://janegilring.wordpress.com/category/print-management/


    That is not what the OP asked.  Please realikze you are asking your own questions.

    The OP is trying to create a GPP to do what the Print Management utility does for us.

    The GPO CmdLet link I posted shows the CmdLets required to create a GPO and ma age it. The question has nothing to do with creating print devices or queues.

    When assigning a shared printer the print spooler installs the correct driver for the shared printer.

    The GPP referenced will attach a shared printer to a user session and can be created with a GPO using CmdLets but it is a bit tricky and unnecessary if we use the Pint Management app.

    Here are some discussions about how to create a GPO/GPP for a printer:

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/fd6f2b22-2bdc-4535-a9b3-6aa0fefa14fc/import-several-printers-in-to-gpo-via-script-or-powershell?forum=winserverpowershell


    \_(ツ)_/

    Thursday, May 31, 2018 5:33 PM
    Moderator
  • Here is a quick example of how to edit that policy using the GPO CmdLets:

    [xml]$xml = get-gpo -Name 'Printer Policy Starter' | Get-GPOReport -ReportType Xml
    $xml.GPO.User.ExtensionData[0].Extension.PrinterConnection

    Add printers to the list and alter the GPO name or other elements and apply the XML as a new or updated GPO.  Use the other GPO CmdLets to link and add filters.

    You will need to know GP, PowerShell and XML to use the GPO CmdLets to create and link a GPO.  Always start with a GPO "starter" as it will create all of the XML sections you will need to modify.  Just create the "Starter" as a Printer GPP with all of the dummy setting you need.

    I recommend creating printer GPPs by function, department or job description and link and filter based on groups.  Now just add the users who need access to the groups they need based on the target of the  group.


    \_(ツ)_/


    Thursday, May 31, 2018 9:24 PM
    Moderator
  • Here is an actual GPP deployment with GPP:

          <Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/Printers" xsi:type="q1:PrintersSettings">
            <q1:Printers clsid="{1F577D12-3D1B-471e-A1B7-060317597B9C}">
              <q1:SharedPrinter clsid="{9A5E9697-9095-436d-A0EE-4D128FDFBCE5}" name="HP LaserJet 4050 Series PCL6" status="HP LaserJet 4050 Series PCL6" image="2" userContext="1" bypassErrors="1" changed=
    "2018-05-31 21:40:17" uid="{CBFDD486-8B97-41D9-ADAC-90FBCC2E1508}">
                <q1:GPOSettingOrder>1</q1:GPOSettingOrder>
                <q1:Properties action="U" comment="" path="\\SBS01\HP LaserJet 4050 Series PCL6" location="" default="0" skipLocal="0" deleteAll="0" persistent="1" deleteMaps="0" port="LPT4:" />
                <q1:Filters>
                  <q1:FilterGroup bool="AND" not="0" name="TESTLNET\testgrp3" sid="S-1-5-21-1997746983-321388823-153608166-2233" userContext="1" primaryGroup="0" localGroup="0" />
                </q1:Filters>
              </q1:SharedPrinter>
            </q1:Printers>
          </Extension>
          <Name>Printers</Name>
        </ExtensionData>

    You can copy and edit or add printer shares and filters using standard XML methods.

    This is all the SDM software does except it also has a database of hints and values and an engine that does the editing that we would do with XML here.


    \_(ツ)_/




    Thursday, May 31, 2018 9:42 PM
    Moderator
  • Not exactly straightforward.  I was trying to do it with set-gpregistryvalue and getting nowhere.  The other problem is how to set the default printer in printmanagement.msc.  It's nice to see the link to the deployed printer gpo in the printmanagement interface, if you go that way.

    ValueName        Key                                                                                                                      Data   Type
    ---------        ---                                                                                                                      ----   ----
    printAttributes  Software\Policies\Microsoft\Windows NT\Printers\PushedConnections\{C01633F4-66E5-4AFA-B7CF-3570D5B0D20D}                    0  DWord
    printerName      Software\Policies\Microsoft\Windows NT\Printers\PushedConnections\{C01633F4-66E5-4AFA-B7CF-3570D5B0D20D}            myprinter String
    serverName       Software\Policies\Microsoft\Windows NT\Printers\PushedConnections\{C01633F4-66E5-4AFA-B7CF-3570D5B0D20D}           \\myserver String
    uNCName          Software\Policies\Microsoft\Windows NT\Printers\PushedConnections\{C01633F4-66E5-4AFA-B7CF-3570D5B0D20D} \\myserver\myprinter String

    (Output from Dave Wyatt's PolicyFileEditor module after setting a deployed printer policy locally.)







    • Edited by JS2010 Friday, June 1, 2018 2:17 PM
    Friday, June 1, 2018 1:32 PM
  • I found an example of changing the server name in printer gpo's using set-adobject, so maybe it's possible to create printers in a similar way.  https://www.craig-tolley.co.uk/2014/09/10/modifying-gpo-printer-deployment-using-powershell/


    • Edited by JS2010 Thursday, June 14, 2018 7:40 PM
    Thursday, June 14, 2018 7:40 PM