Jump to content

Recommended Posts

Posted

  Jos said:

Maybe you can explain what information you are looking for?

There are many scriptlets posted that query AD user informations etc.

Jos

Thanks for the quick reply.

I am trying to create a script that will auto fill a form and register it using the current users first name, last name and username.

I have been able to query the username localy using $usrname=@username, Now i need to query active directory to recieve the GivenName (firstname) and Sn (lastname).

I have found alot of scripts on here but I am new and learning.

From this point which will conect to my AD. How do i tell ad to give me the GivenName and SN output based on the logged in user by the $username.

Local $objCommand = ObjCreate("ADODB.Command")

Local $objConnection = ObjCreate("ADODB.Connection")

$objConnection.Provider = "ADsDSOObject"

$objConnection.Open ("Active Directory Provider")

$objCommand.ActiveConnection = $objConnection

Local $strBase = "<LDAP://dc=,dc=,dc=,dc=>"

Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))"

Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName"

Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree"

$objCommand.CommandText = $strQuery

$objCommand.Properties ("Page Size") = 100

$objCommand.Properties ("Timeout") = 30

$objCommand.Properties ("Cache Results") = False

$ADS_SCOPE_SUBTREE = 2

$objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE

Local $objRecordSet = $objCommand.Execute

Thanks

Posted (edited)

Hi lonswe01,

you need something like:

#include <adfunctions.au3>
$ou = "DC=microsoft,DC=com"                     ; Root of your AD
_ADGetObjectsInOU($User, $ou, "(&(objectCategory=user)(sAMAccountName=" & @username & "))", 2, "GivenName,Sn")

Returns an array with the required information.

Have a look at #583178 where you'll find some tools to inspect your AD and further info on how to create LDAP queries.

You can get adfunctions.au3 from http://www.autoitscript.com/forum/index.ph...st&id=22018 or http://www.autoitscript.com/forum/index.php?showtopic=37378

HTH

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Heres a good snippet, i did not write this code as i was given this some time ago:

Func GetFullName($sUserName)
    $colItems = ""
    $strComputer = "localhost"

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName & "'", "WQL", 0x10 + 0x20)

    If IsObj($colItems) Then
        For $objItem In $colItems
            Return $objItem.FullName
        Next
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc   ;==>GetFullNameoÝ÷ غ()í¢Ø^ªê-Ëb½àâ­ç-¢¼ªºm·v)ç{¦¦W¬r¸©¶Ê'¶ººÞÚZèh {g(֢ƥ¢Úr^Z«{*.¶§Ê¢+eG­+ºÚ"µÍÚ[ÛYH    ØY[Ý[ÛË]LÉÝÂÛÛÛÛUÜ]JÐQÙ]ØXÝ]X]JÙ[YK    ][ÝÙÚ][[YI][ÝÊI[ÈÔBÛÛÛÛUÜ]JÐQÙ]ØXÝ]X]JÙ[YK ][ÝÜÛ][ÝÊI[ÈÔ
Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...