darkleton Posted March 5, 2007 Share Posted March 5, 2007 I know Active Directory questions have been asked before, and I have searched the forums but can't find anything relating to my problem. I have converted an old batch file to AU3 to create users on a domain and it works fine. The things the batch could never do and had to be done manually were: Forcing user to change password at next logon, Changing profile path from local to remote Moving user to specific OU I've found on the Microsoft site a few VB scripts that can do at least one of the three. I used the VB2AU3 converter and came out with this: $UserObj = ObjGet("LDAP://cn=" & $initial_st & $surname_st & ",ou=Users,dc=mydomain,dc=co,dc=uk") $UserObj.Put ("pwdLastSet", 0) $UserObj.SetInfo() When I run it, I get an error stating that the variable must be of type OBJECT. I don't know exactly how to get my script to interact with AD properly. If I can use the UserObj line to set to the account just created, and then knew the correct syntax for these strings then it would make things a lot easier for me. Any help would be very much appreciated Thanks Link to comment Share on other sites More sharing options...
Developers Jos Posted March 5, 2007 Developers Share Posted March 5, 2007 I know Active Directory questions have been asked before, and I have searched the forums but can't find anything relating to my problem. I have converted an old batch file to AU3 to create users on a domain and it works fine. The things the batch could never do and had to be done manually were: Forcing user to change password at next logon, Changing profile path from local to remote Moving user to specific OU I've found on the Microsoft site a few VB scripts that can do at least one of the three. I used the VB2AU3 converter and came out with this: $UserObj = ObjGet("LDAP://cn=" & $initial_st & $surname_st & ",ou=Users,dc=mydomain,dc=co,dc=uk") $UserObj.Put ("pwdLastSet", 0) $UserObj.SetInfo() When I run it, I get an error stating that the variable must be of type OBJECT. I don't know exactly how to get my script to interact with AD properly. If I can use the UserObj line to set to the account just created, and then knew the correct syntax for these strings then it would make things a lot easier for me. Any help would be very much appreciated Thanks This way works for me ... Are you sure you gave the correct CN ? Does your ObjGet return an object ? 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. Link to comment Share on other sites More sharing options...
darkleton Posted March 5, 2007 Author Share Posted March 5, 2007 This way works for me ...Are you sure you gave the correct CN ?Does your ObjGet return an object ?it should be in the format of cn=username,ou=ou-they-are-in,dc=mydomain,dc=namecorrect?i don't know if it returns anything, but it does say that the error is on the PwdLastSet line, not the initial line. How would I find out if its returning an object correctly?I know I know, I'm stupid Link to comment Share on other sites More sharing options...
ptrex Posted March 5, 2007 Share Posted March 5, 2007 @darkleton 2 things to get you started : This is a list of AD functions UDF which might come in handy. Regarding the Errors you get : Add the COM handler and it will tell you axactly what is going wrong in your script. ; Initialize COM error handler add in the beginning of the script $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Add at the end of the script ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Hope this gets you going. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
darkleton Posted March 5, 2007 Author Share Posted March 5, 2007 thanks to both of you for pointing me in the right direction. I've now got the password reset next logon and home directory flags working great. The last thing i need is to move the user to a different OU. This is the VBS code: Set objOU = GetObject("LDAP://ou=sales,dc=na,dc=fabrikam,dc=com") objOU.MoveHere _ "LDAP://cn=BarrAdam,OU=hr,dc=na,dc=fabrikam,dc=com", vbNullString I tried converting this too, and then tried (stupidly) changing it to how I thought it would work, and ended up with this: $OuObj = ObjGet("LDAP://CN=OU-TO-MOVE-TO, DC=mydomain, DC=co, DC=uk") $OuObj.MoveHere("LDAP://CN=" & $initial_st & $surname_st & ", CN=Users, DC=mydomain, DC=co, DC=uk") I would assume that the top line sets the OU to move to, and the bottom line is the username and OU where they currently reside? If so then I get an error (as described by that COM error thing I put in) saying that no such object exists. This is like the final piece of the puzzle. If I can get it to move to a new OU properly then v1.0 of my first attempt is done Link to comment Share on other sites More sharing options...
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