Thursday, December 22, 2005

Export Published Printers to File

Here's a script courtesy of Microsoft, slightly modified by me to direct output to a file . It will export the published printers in AD to a comma delimited text file (printers.txt below) along with the associated server.

'**********
'export published printers to file
'from webmaxtor.blogspot.com
'**********

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
& " 'LDAP://DC=yourdomain,DC=com' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile("Printers.txt", True)

Do Until objRecordSet.EOF
myFile.Writeline objRecordSet.Fields("serverName").Value & "," & objRecordSet.Fields("printerName").Value
objRecordSet.MoveNext
Loop

myFile.Close

'**********
'end of script
'**********

The MS Scripting center site has boat load of this good stuff.

No comments:

Post a Comment