add printer network to OU RRS feed

  • Pregunta

  • Good afternoon, I have a problem to add network printers.

    I'm doing a script to map network printers that corresponds to an OU that I present the problem is that I add the printers.

    I have a txt file which is the OU and printers for each one, if anyone can help me be grateful I'm new to this world of script.

    leave the code to see if anyone gives me a solution.


    'Set global script objects and variables
    Set wshShell = WScript.CreateObject("WScript.Shell")
    Set wshNetwork = WScript.CreateObject("WScript.Network")
    Set wshObj = WScript.CreateObject("Scripting.FileSystemObject")

    '------------------------------- VARIABLES de usuario  --------------------------------
    strNetworkPath = "C:\Copia de impresoras1.txt"
    '----------------------------- +++++++++++++++++ ------------------------------

    'On Error Resume Next

    Call DisconnectNetworkPrinters()
    MsgBox "Ejecuta asignar prn"
    Call ConnectPrinters(strNetworkPath, wshNetwork.computername)


    Sub DisconnectNetworkPrinters()
      Set arPrinters = wshNetwork.EnumPrinterConnections

      For i = 0 to (arPrinters.Count - 1) Step 2
        If (Left(arPrinters.Item(i + 1), 2) = "\\") Then
          wshNetwork.RemovePrinterConnection arPrinters.Item(i + 1)
        End If
    End Sub


    Agregar impresora por OU

    Sub ConnectPrinters(strListFile, strCompname)
    Dim arrLinParts()
    Dim strCadTratar
      Set ListFile = wshObj.OpenTextFile(strListFile, 1)
      Do While ListFile.AtEndOfStream <> True
        strCadTratar = ListFile.ReadLine
        arrLineParts = Split(strCadTratar, Space(1))
        MsgBox strCompname & " " & strCadTratar
        If UCase(strCompname) = UCase(arrLineParts(0)) Then
          For i = 0 To UBound(arrLineParts)
            If arrLineParts(i) <> "" Then
              wshNetwork.AddWindowsPrinterConnection UCase(arrLineParts(i))
            End If
          If arrLineParts(1) <> "" Then
            wshNetwork.SetDefaultPrinter UCase(arrLineParts(1))
          End If
        End If
    End Sub


    domingo, 1 de mayo de 2011 17:01


  • Hi Efe27,

          Has you AD Schema been updated with 2008 R2 extensions?  If so, and you have a 2008 R2 server on your network you can install the Print and Document Services role to handle deploying printers by OU.  This method is MUCH easier that scripting.  Here is a screen shot of the deployment console:

    If you are not running an 2008 R2 Schema  (and I will stress this funcionality alone is worth the upgrade, our printer deployment problems were virutually eliminated after implementing this)

    However, if you are not able to upgrade your schema,  you can deploy printer via OU, using a simpler .vbs script, like the one available here:

    Then attaching a script to a New GPO assigned to each OU, under computer configuration > windows settings > scripts >startup

    and finally enabling loopback processing on each GPO, so that the script will be applied to th user's settings:

    • Propuesto como respuesta Andrew Sheehan martes, 29 de mayo de 2012 8:35
    • Marcado como respuesta Uriel Almendra miércoles, 28 de agosto de 2013 20:24
    martes, 29 de mayo de 2012 8:35