skid
Goto Top

Aus dem Anmeldenamen das CN ermitteln

Hi,

suche in VB oder VBS eine Lösung um aus einem Domänen-Anmeldenamen (samAccountName)
z.B. Max123 den CN des Users, z.B. Max Mustermann, zu ermitteln.

Vielleicht hat jemand eine Lösung ?!

Gruss

SKID

Content-Key: 40328

Url: https://administrator.de/contentid/40328

Printed on: April 18, 2024 at 23:04 o'clock

Member: SlainteMhath
SlainteMhath Sep 18, 2006 at 08:02:14 (UTC)
Goto Top
Set objConnection = CreateObject("ADODB.Connection")  
Set objCommand    = CreateObject("ADODB.Command")  
Set objNetwork    = CreateObject("WScript.Network")  ' <= edit  

objConnection.Open "Provider=ADsDSOObject;"  
samAccountName = objNetwork.UserName     

objCommand.ActiveConnection = objConnection
' hier den Base DN noch anpassen! <LDAP://....>  
objCommand.CommandText = "<LDAP://dc=domain,dc=local>;(&(objectCategory=User)(samAccountName=" & samAccountName & "));CN"  
                         
Set objRecordset = objCommand.Execute

If objRecordset.RecordCount = 1 Then	
    strCN=objRecordset.fields("CN").value      
end if

wscript.echo strCN

Sollte so funktionieren. Du musst lediglich den Base DN entsprechend ändern
Member: skid
skid Sep 18, 2006 at 08:45:02 (UTC)
Goto Top
Hi,

sieht schon mal ganz gut aus.

Bekomme nur die Meldung:

Laufzeitfehler in Microsoft VBScript: Objekt erforderlich: 'objNetwork'
Member: SlainteMhath
SlainteMhath Sep 18, 2006 at 08:50:45 (UTC)
Goto Top
Uups, da is wohl beim Copy&Paste ne zeile verlorengegangen face-smile

Ich hab den Code entsprechend editiert.
Member: skid
skid Sep 18, 2006 at 09:08:36 (UTC)
Goto Top
Alles Klar - Dank Dir !!

Jetzt funktionierts face-smile

Ich sags ja, immer dieses C&P Programming face-wink