| Active Directory: VBscript to enumerate the roaming profile size of all users in Active Directory | Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory |
Topic of today is printing.
I have made a script that enumerates all Active Directory published printers.
By adding or removing attributes from arrAttributes you can change the output to your specific needs.
Follow the next steps to run the script (no admin rights needed):
* open your favorite text editor
* copy and paste the script into the editor
* save the script (for example c:\temp\adprinters.vbs)
* open a command prompt
* go to “c:\temp”
* give “cscript adprinters.vbs” (without quotes) and enter
The script:
' Name : adprinters.vbs
' Description : script to enumerate all Active Directory published printers
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 16-03-2010
' Level : intermediate
arrAttributes = Array("name","printerName","location","serverName")
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
Set objRootDSE = Nothing
strFilter = "(objectClass=printQueue)"
strAttributes = Join(arrAttributes,",")
Wscript.Echo Join(arrAttributes,";")
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
On Error Resume Next
strTempOutput = ""
For i = 0 To Ubound(arrAttributes)
strTempOutput = strTempOutput & " ; " & adoRecordset.Fields(arrAttributes(i)).Value
strOutput = Mid(Ltrim(strTempOutput),3)
Next
Wscript.Echo strOutput
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
When you have problems/questions please post a reply, you can also rate the script.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
VN:F [1.9.3_1094]
VN:F [1.9.3_1094]
Active Directory: VBscript to enumerate all Active Directory published printers, 10.0 out of 10 based on 1 rating
Posted by dirk adamsky at 13:50
Tagged with: active directory, attribute, command prompt, cscript, enumerate, list, printer, printers, printqueue, vb, vbs, vbscript





Recent Comments