Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help getting portName value out of AD 1

Status
Not open for further replies.

KenDCFS

MIS
Jan 24, 2002
7
0
0
US
Has anyone been able to produce the portName and description to the output file. I keep getting a type mismatch.

Any help or ideas would be appeciated.

' Get Domain name from RootDSE object - no need to specify local server names.

Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")

'The line below is a reasuurance line - place a ' to comment it out
'WScript.Echo strDomain ' This is Extra line Guy put in to test

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")

' --- CHANGE THE OUTPUT FILE LOCATION
Set objLogFile = objFSO.OpenTextFile("C:\111\vbs\Printer_List.csv", ForAppending, True)

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
' Now we get the print Queue objects
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName, description, driverName, location, portName, uNCName from " _
& " 'LDAP://" & strDomain & " ' where objectClass='printQueue' "
' Adjust the command properties
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

' Consume each row in the recordset results and write a line to the file

Do Until objRecordSet.EOF
Wscript.Echo "Printer name: " & objRecordSet.Fields("printerName")
Wscript.Echo "portname: " & objRecordSet.Fields("portName")


objLogFile.Write(objRecordSet.Fields("serverName").Value & "," & objRecordSet.Fields("printerName").Value & "," & objRecordSet.Fields("uNCName").Value & "," & objRecordSet.Fields("driverName").Value & "," & objRecordSet.Fields("location").Value & "," + objRecordSet.Fields("portName.Port").Value)
objLogFile.Writeline
objRecordSet.MoveNext
Loop

MsgBox("Done Processing")
 
And what about this ?
Join(objRecordSet.Fields("portName"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top