2009-05-21 6 views
1

Dans Active Directory, il y a un onglet appelé « Dial-In », et sous cet onglet est un bouton de commande radio avec trois paramètres:Comment puis-je obtenir le paramètre Autorisation de numérotation Active Directory à partir de LDAP à l'aide de VBScript?

Allow Access 
Deny Access 
Control access through remote access policy 

Je voudrais écrire un VBScript pour prendre un nom d'utilisateur et renvoyez le paramètre pour cet utilisateur. (Je suis en train de modifier un VBScript existant, c'est pourquoi je suis obligé d'utiliser cet outil).

Quelle est la meilleure façon de faire cela?

Répondre

2

Voici la meilleure solution que j'ai trouvée. Il est facile de le modifier pour afficher le paramètre pour tous les utilisateurs.

Main 

Function Main 
    'Usage: cscript /nologo lookup.vbs mydomain username 
    Wscript.Echo CanDialIn(Wscript.Arguments(0), Wscript.Arguments(1)) 
    Main = 0 
End Function 

Function CanDialIn(domainname, username) 
    'Take a user name and query whether they have permission to Dial in or not 
    'http://www.microsoft.com/technet/scriptcenter/resources/qanda/aug05/hey0825.mspx 
    Const ADS_SCOPE_SUBTREE = 2 
    Dim objConnection 
    Dim objCommand 
    Dim objRecordSet 

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

    objCommand.Properties("Page Size") = 1000 
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

    'Three possible values for msNPAllowDialin: 
    'TRUE = "Allow Access" 
    'FALSE = "Deny Access" 
    'EMPTY = "Control access through remote access policy" 
    objCommand.CommandText = _ 
    "SELECT msNPAllowDialin FROM 'LDAP://dc=" & domainname & ",dc=com' WHERE objectCategory='user' AND sAMAccountName = '" & username & "'" 
    On Error Resume Next 
    Set objRecordSet = objCommand.Execute 
    if objRecordSet.EOF then 
    CanDialIn = "Could not find user " & username 
    else 
    if objRecordSet.Fields("msNPAllowDialin").Value = True then 
     CanDialIn = "Allow" 
    else 
     if objRecordSet.Fields("msNPAllowDialin").Value = False then 
     CanDialIn = "Deny" 
     else 
     CanDialIn = "Control" 
     end if 
    end if 
    end if 
End Function 
Questions connexes