2014-01-15 61 views
0

我對Active Directory和WSH腳本用於查詢使用LDAP有點不熟悉。如果我將家庭電話字段作爲參數提供給AD/LDAP查詢,我有奇怪的請求能夠自動執行(僅通過VBScript)從AD服務器獲取Active Directory用戶名。通過傳遞家庭電話VBScript查找Active Directory用戶名

有誰知道這是可能做到的嗎?

謝謝!

+1

[獲取基於用戶名AD詳情]的可能的複製(http://stackoverflow.com/questions/21110232/getting-ad-details-based -on-用戶名)。只需用'homePhone'屬性替換'sAMAccountName'屬性即可。 –

+0

如果您想要一些更常見的字段的可視列表,您可以檢查一系列有關Outlook中的LDAP屬性的帖子[http://www.jigsolving.com/activedirectory/user-account-attributes-part- 1] - 它還涵蓋了Active Directory for Users and Computers中的一些LDAP屬性。 – Damien

+0

謝謝你,但不幸的是,我沒有用家用電話查詢用戶名@AnsgarWiechers –

回答

0

我已經找到了有興趣的解決方案:

Set rootDSE = GetObject("LDAP://RootDSE") 
base = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">" 
'filter on user objects with the given account name 
fltr = "(&(objectClass=user)(objectCategory=Person)" & _ 
     "(homePhone=yourphone))" 
'add other attributes according to your requirements 
attr = "distinguishedName,sAMAccountName" 
scope = "subtree" 

Set conn = CreateObject("ADODB.Connection") 
conn.Provider = "ADsDSOObject" 
conn.Open "Active Directory Provider" 

Set cmd = CreateObject("ADODB.Command") 
Set cmd.ActiveConnection = conn 
cmd.CommandText = base & ";" & fltr & ";" & attr & ";" & scope 

Set rs = cmd.Execute 
Do Until rs.EOF 
    WScript.Echo rs.Fields("sAMAccountName").Value 
    rs.MoveNext 
Loop 
rs.Close 

conn.Close 
+1

..但這就是Ansgar建議的? – Damien

相關問題