lonswe01 Posted October 16, 2008 Posted October 16, 2008 Does anyone have a script that will query AD based on the logged on users $username. Thanks
Developers Jos Posted October 16, 2008 Developers Posted October 16, 2008 Maybe you can explain what information you are looking for? There are many scriptlets posted that query AD user informations etc. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
lonswe01 Posted October 16, 2008 Author Posted October 16, 2008 Maybe you can explain what information you are looking for?There are many scriptlets posted that query AD user informations etc.Jos
lonswe01 Posted October 16, 2008 Author Posted October 16, 2008 Maybe you can explain what information you are looking for?There are many scriptlets posted that query AD user informations etc.JosThanks 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.ExecuteThanks
water Posted October 17, 2008 Posted October 17, 2008 (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=37378HTH Edited October 17, 2008 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
jokke Posted October 17, 2008 Posted October 17, 2008 (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 October 17, 2008 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.
lonswe01 Posted October 17, 2008 Author Posted October 17, 2008 Thanks a lot. This informations is verry helpfull.
lonswe01 Posted October 17, 2008 Author Posted October 17, 2008 Thanks alot. This information is very helpful.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now