Sign in to follow this  
Followers 0
lonswe01

Query GivenName and Sn from active directory for logged in user

8 posts in this topic

Does anyone have a script that will query AD based on the logged on users $username.

Thanks

Share this post


Link to post
Share on other sites



Maybe you can explain what information you are looking for?

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

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Maybe you can explain what information you are looking for?

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

Jos

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  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:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  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.

Share this post


Link to post
Share on other sites

Thanks a lot. This informations is verry helpfull.

Share this post


Link to post
Share on other sites

Thanks alot. This information is very helpful.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0