简体   繁体   English

vbscript,通过架构属性验证用户是否在活动目录中

[英]vbscript, validate a user is in active directory by schema attribute

I'm trying to write a vb script that prompts a user for a schema attribute which I'll call bID and checks that the person with that bID is in active directory. 我正在尝试编写一个vb脚本,该脚本提示用户输入一个架构属性,我将其称为bID,并检查具有该bID的人是否在活动目录中。 I really have no idea how to get started, there are plenty of examples on how to query active directory users but I havent found a good one regarding checking against specific attributes. 我真的不知道如何开始,有很多关于如何查询活动目录用户的示例,但是我还没有找到关于检查特定属性的好方法。 Any help/suggestions are greatly appreciated! 任何帮助/建议都将不胜感激!

UPDATE: ok heres my code so far, doesnt error out and returns 0, but I dont get a wscript.echo of the distinguished name for some reason. 更新:到目前为止,我的代码可以正常运行,不会出错并返回0,但是由于某种原因,我没有得到专有名称的wscript.echo。 I included a few debugging wscript.echo's and it seems to never get into the while loop. 我包括了一些调试wscript.echo的程序,它似乎永远不会进入while循环。 Any ideas? 有任何想法吗?

Option Explicit

GetUsers "CN=users,DC=example,DC=example,DC=example,DC=com","123456"

Function GetUsers(domainNc, ID)
    Dim cnxn    
    Set cnxn = WScript.CreateObject("ADODB.Connection")    
    cnxn.Provider = "ADsDSOObject"    
    cnxn.Open "Active Directory Provider"    
    Dim cmd    
    Set cmd = WScript.CreateObject("ADODB.Command")    
    cmd.ActiveConnection = cnxn    
    cmd.CommandText = "<LDAP://" & domainNc & ">;(&(objectCategory=user)(objectClass=user)    (employeeNumber=" & ID & "));distinguishedName;subtree"
    WScript.Echo cmd.CommandText
    cmd.Properties("Page Size") = 100    
    cmd.Properties("Timeout") = 30    
    cmd.Properties("Cache Results") = False    
    WScript.Echo "setting cmd.properties"
    Dim rs
    Set rs = cmd.Execute
    WScript.Echo "rs object set"
    While Not rs.eof
        On Error Resume Next
        WScript.Echo "while loop start"
        Wscript.Echo rs.fields("distinguishedName".Value)
        rs.MoveNext
        If (Err.Number <> 0) Then       
     WScript.Echo vbCrLf& "Error # "& CStr(Err.Number)& " "& Err.Description
        Else
      On Error GoTo 0
        End If 
    Wend
    WScript.Echo "while loop end"
    rs.close    
    WScript.Echo "rs object closed"
    cnxn.Close    
    Set rs = Nothing    
    Set cmd = Nothing    
    Set cnxn = Nothing 
    End Function

Here's some vbscript that will find all users with bID=FooVal and write their DN out 这是一些vbscript,它将查找所有bID = FooVal的用户并写出他们的DN

Function GetUsers(domainNc, bIdVal)
    Dim cnxn
    Set cnxn = WScript.CreateObject("ADODB.Connection")
    cnxn.Provider = "ADsDSOObject"
    cnxn.Open "Active Directory Provider"

    Dim cmd
    Set cmd = WScript.CreateObject("ADODB.Command")
    cmd.ActiveConnection = cnxn

    cmd.CommandText = "<LDAP://" & domainNc & ">;(&(objectCass=user)(objectCategory=person)(bid=" & bidVal & "));distinguishedName;subtree"
    cmd.Properties("Page Size") = 100
    cmd.Properties("Timeout") = 30
    cmd.Properties("Cache Results") = False

    Dim rs
    Set rs = cmd.Execute

    While Not rs.eof 
        Wscript.Echo rs.fields("distinguishedName").Value

        rs.MoveNext
    Wend 

    rs.close
    cnxn.Close

    Set rs = Nothing
    Set cmd = Nothing
    Set cnxn = Nothing 
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM