В. Как использовать сценарий для поиска принтеров, перечисленных в Active Directory (AD)?

О.

Const ADS_SCOPE_SUBTREE = 2 
  
' Убедитесь, что указаны все необходимые аргументы.
If Wscript.Arguments.Count < 1 Then 
    Wscript.Echo "Arguments  required. For example:" & vbCrLf 
_ 
        & "cscript searchprinters.vbs dc=savilltech,dc=com" 
    Wscript.Quit(0) 
End If 
  
strRootSearch = Wscript.Arguments(0) 
  
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://" & strRootSearch & "' where objectClass='printQueue'" 
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 
Do Until objRecordSet.EOF 
    Wscript.Echo "Printer Name: " & 
objRecordSet.Fields("printerName").Value 
    Wscript.Echo "Server Name: " & 
objRecordSet.Fields("serverName").Value 
    objRecordSet.MoveNext 
Loop 

 

Ниже приведен образец выполнения сценария:

C:>cscript searchprinters.vbs dc=savilltech,dc=com
Printer Name: Phaser860
Server Name: DALSDC01.savilltech.com
Printer Name: CWIS
Server Name: DALSDC01.savilltech.com
Printer Name: Project
Server Name: DALSDC01.savilltech.com
Printer Name: HR
Server Name: DALSDC01.savilltech.com
Printer Name: HP LaserJet 4M Plus
Server Name: DALSDC01.savilltech.com
Printer Name: Project
Server Name: dalsxc01.savilltech.com