water Posted April 6, 2015 Posted April 6, 2015 You want to move OUs including all sub-OUs and containers to a new OU? Or just the computers in this source OUs and sub-OUs? 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
Rijswijker Posted April 6, 2015 Posted April 6, 2015 (edited) Yes, I want move OUs including all sub-OUs and containers to a new OU. Edited April 6, 2015 by Rijswijker
water Posted April 6, 2015 Posted April 6, 2015 I'm not sure this is possible (I just have read-only access to our AD). Could you please add _AD_ErrorNotify(2) at the top of your script so we get better error information? 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
Rijswijker Posted April 6, 2015 Posted April 6, 2015 I'm not sure this is possible (I just have read-only access to our AD). Could you please add _AD_ErrorNotify(2) at the top of your script so we get better error information? The result
water Posted April 6, 2015 Posted April 6, 2015 I did some research and found a script that confirms that moving an OU should be possible. At the moment function _AD_MoveObject is designed to move CN-objects (user, group, computer ...) but not OUs. But it should be possible to adapt the function to move OUs as well. If you have some spare time and are willing to do some tests then I'm going to modify the function. 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
Rijswijker Posted April 6, 2015 Posted April 6, 2015 I have time, i am now on 80% of the final program. I have to do a few tests, one test more or less does not matter.
water Posted April 6, 2015 Posted April 6, 2015 I will do some tests tomorrow and hope to come up with a solution in the next few days. 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
water Posted April 7, 2015 Posted April 7, 2015 This is the code I've found on the web translated to AutoIt. #include <AD.au3> _AD_Open() $sSourceOU = "OU=Computers,OU=carpark,OU=Parking,DC=sd0500017,DC=carpark" ; The OU to be moved $sTargetOU = "OU=TEMP,DC=sd0500017,DC=carpark" Local $oTargetOU = __AD_ObjGet("LDAP://" & $sAD_HostServer & "/" & $sTargetOU) ConsoleWrite(@error & @CRLF) $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, Null) ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, Default) ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, "") ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU) ConsoleWrite(@error & @CRLF) _AD_Close() One of the 4 MoveHere variants should work. PLEASE CHECK $sSourceOU and $sTargetOU in advance!! Could you please test and post the results? 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
Rijswijker Posted April 8, 2015 Posted April 8, 2015 (edited) This is the code I've found on the web translated to AutoIt. #include <AD.au3> _AD_Open() $sSourceOU = "OU=Computers,OU=carpark,OU=Parking,DC=sd0500017,DC=carpark" ; The OU to be moved $sTargetOU = "OU=TEMP,DC=sd0500017,DC=carpark" Local $oTargetOU = __AD_ObjGet("LDAP://" & $sAD_HostServer & "/" & $sTargetOU) ConsoleWrite(@error & @CRLF) $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, Null) ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, Default) ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU, "") ; $oTargetOU.MoveHere("LDAP://" & $sAD_HostServer & "/" & $sSourceOU) ConsoleWrite(@error & @CRLF) _AD_Close() One of the 4 MoveHere variants should work. PLEASE CHECK $sSourceOU and $sTargetOU in advance!! Could you please test and post the results? Error 1st: Type mismatch 2nd: Parameter not optional 3rd: An invalid directory pathname was passed 4th: Invalid number of parameters The Source and Target OU's are ok. Edited April 8, 2015 by Rijswijker
water Posted April 8, 2015 Posted April 8, 2015 Thanks for the reply! What is the value of @error for thise 4 variantes? 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
Rijswijker Posted April 10, 2015 Posted April 10, 2015 (edited) Thanks for the reply! What is the value of @error for thise 4 variantes? Error 1st: Type mismatch 0 and -2147352571 2nd: Parameter not optional 0 and-2147352561 3rd: An invalid directory pathname was passed 0 and-2147352567 4th: Invalid number of parameters 0 and-2147352562 Sorry for my late response. Edited April 10, 2015 by Rijswijker
water Posted April 11, 2015 Posted April 11, 2015 I will post the VB script so we can see if the problem is AD or AutoIt related. 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
Rijswijker Posted May 7, 2015 Posted May 7, 2015 I will post the VB script so we can see if the problem is AD or AutoIt related.I finished my program, but before I throw away my virtual machines I would still perform those tests.Can you post the VB Scripts?
water Posted May 7, 2015 Posted May 7, 2015 Sorry, forgot to post. Will do tomorrow. 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
water Posted May 9, 2015 Posted May 9, 2015 The VB script I was talking about can be found here. 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
BigNoter Posted March 22, 2016 Posted March 22, 2016 (edited) Hi, I need to remove all groups from "Member Of" tab, and add two groups to it, for a list of users in an OU. How can I do that...? Anyone got this piece of code or similar, will be appreciated. TIA Edited March 22, 2016 by BigNoter
water Posted March 22, 2016 Posted March 22, 2016 In short: Grab the list of users from the OU by using function _AD_GetObjectsInOU. One of the returned properties should be "memberOf". Loop through the resulting array of users. Split property "memberOf" into an array (separator is "|"). Loop through this second array and call function _AD_RemoveUserFromGroup for each of the groups. Then call _AD_AddUserToGroup to add new groups to the user. 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
BigNoter Posted March 22, 2016 Posted March 22, 2016 2 minutes ago, water said: In short: Grab the list of users from the OU by using function _AD_GetObjectsInOU. One of the returned properties should be "memberOf". Loop through the resulting array of users. Split property "memberOf" into an array (separator is "|"). Loop through this second array and call function _AD_RemoveUserFromGroup for each of the groups. Then call _AD_AddUserToGroup to add new groups to the user. Thnx for the quick reply. This pseudo code helps, but a little. last time I did code was, as I remember, 2007...! If you, or anybody, provide a piece of code will help a lot. TIA
water Posted March 22, 2016 Posted March 22, 2016 Untested! Please make sure to test on a test system only!! #include <AD.au3> Global $sOU = "" ; OU to process Global $aObjects, $aGroups ; Open Connection to the Active Directory _AD_Open() If @error Then Exit MsgBox(16, "AD", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) ; Get a list of users in the specified OU (subtree) $aObjects = _AD_GetObjectsInOU($sOU, "(&(objectcategory=person)(objectclass=user))", 2, "sAMAccountName,memberof") If @error > 0 Then Exit MsgBox(16, "AD", "Function _AD_GetObjectsInOU encountered a problem. @error = " & @error & ", @extended = " & @extended) ; Process all users For $i = 1 To $aObjects[0][0] $aGroups = StringSplit($aObjects[$i][1], "|") For $j = 1 To $aGroups[0] ; Remove User from group _AD_RemoveUserFromGroup($aGroups[$j], $aObjects[$i][0]) If @error > 0 Then Exit MsgBox(16, "AD", "Function _AD_RemoveUserFromGroup encountered a problem. @error = " & @error & ", @extended = " & @extended) Next ; Add User to new groups (repeat the statement for each group to be added) _AD_AddUserToGroup(">>Set groupname here<<", $aObjects[$i][0]) If @error > 0 Then Exit MsgBox(16, "AD", "Function _AD_AddUserToGroup encountered a problem. @error = " & @error & ", @extended = " & @extended) Next _AD_Close() BigNoter 1 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
BigNoter Posted March 23, 2016 Posted March 23, 2016 I got this error, which I don't know what does it mean! Function _AD_GetObjectsInOU encountered a problem. @error = 1, @extended = 0 TIA
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