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")
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")