Jump to content

Recommended Posts

Posted

I am trying to write a script that does the following

1. List all computer accounts in a specified OU / CN

2. Do some logic on each Computer object

3. Move the computer account to an OU based on the results from step 2.

I have looked at an ADFunctions include I found a while ago but what I want to do seems to be beyond the scope of this include file.

I have VBS scripts that can do Step 1 and 3 but I am not good at VB so struggling to get the output into a text file I can then read into AutoIT.

I will beable to get this working as a dual VB / AutoIt script but decided to ask the Forum if there is a way to do this all in AutoIt to make this job easier. All I need to do is specify which OU ort CN I will be working with - Read the results into an array. I will beable to script the analysing the array etc I then just need to know how to move the computer account from one ou/CN to a different OU in AutoIt.

Thanks for any assistance..

Posted

Perhaps you can post the VBS scripts that you found and someone on the forums can translate it for you. There is also a VBS to Autoit converter in the example scripts forum.

Posted

Ad 1)

I would use something like:

_ADGetObjectsInOU($asUser, $sOU, "(&(objectCategory=computer)(operatingsystem=*Windows NT*))", 2, "objectname,operating sys")oÝ÷ Ù8b³¥ø¥ªëk-7髱êðØmêÞ²ém²íê®z¼Mú°å2¢ç^~)Þ«zÚ,µªí{axí­çwv(¹Æ§ºÇ­çîËb¢pEéÚãç-&¶uû§rبÅb±©¨½ì"¶§¶¬jgQ*2¢ë"r«Þ¶!jx¶­j¸´å4ߪ%uú§jëh×6; _ADRenameObject
; Takes a FQDN of an Object and a new Display name.
; Renames the object.
; Returns 0 for success, 1 if the OU object was not found.
Func _ADRenameObject($oldfqdn, $newdisplayname)
    $OUName = StringTrimLeft($oldfqdn, StringInStr($oldfqdn, "OU=") - 1)
    
    $obj_OU = _ADObjGet("LDAP://" & $strHostServer & "/" & $OUName)
    If IsObj($obj_OU) Then
        $newdisplayname = StringReplace($newdisplayname, ",", "\,")
        $obj_OU.MoveHere("LDAP://" & $oldfqdn, "CN=" & $newdisplayname)
        Return 0
    Else
        SetError(1)
        Return @error
    EndIf
EndFunc   ;==>_ADRenameObject

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

 

Posted

Perhaps you can post the VBS scripts that you found and someone on the forums can translate it for you. There is also a VBS to Autoit converter in the example scripts forum.

I see where you are going with this ... I have the UDF and have tried something along the lines of what you have suggested. I keep getting Com errors when running the script with Variable must be a sype of object. I have tried declaring the Variables and putting a AD path into the variable I want to search and this still fails.

I have tried the following ..

#include <AdFunctions.au3>

Dim $asUser

Dim $OU = "CN=Computers,DC=MyDom,DC=co,DC=uk"

_ADGetObjectsInOU($asUser, $OU)

;_ADGetObjectsInOU($asUser, $OU, "(&(objectCategory=computer)(operatingsystem=*Windows NT*))", 2, "objectname,operating sys")

_ArrayDisplay($asuser)

Posted

Looked for other examples and appeared to get it working with

Global $user

$ou = "CN=computers,DC=MyDom,DC=co,DC=uk" ; Root of your AD, e.g. DC=microsoft,DC=com

_ADGetObjectsInOU($User, $ou, "(&(objectCategory=computer))", 2)

_ArrayDisplay($user)

Returns an array with my list of computers, - Just need to get the move script working now..

Thanks

  • 2 weeks later...
Posted

Ad 1)

I would use something like:

_ADGetObjectsInOU($asUser, $sOU, "(&(objectCategory=computer)(operatingsystem=*Windows NT*))", 2, "objectname,operating sys")oÝ÷ Ù8b³¥ø¥ªëk-7髱êðØmêÞ²ém²íê®z¼Mú°å2¢ç^~)Þ«zÚ,µªí{axí­çwv(¹Æ§ºÇ­çîËb¢pEéÚãç-&¶uû§rبÅb±©¨½ì"¶§¶¬jgQ*2¢ë"r«Þ¶!jx¶­j¸´å4ߪ%uú§jëh×6; _ADRenameObject
; Takes a FQDN of an Object and a new Display name.
; Renames the object.
; Returns 0 for success, 1 if the OU object was not found.
Func _ADRenameObject($oldfqdn, $newdisplayname)
    $OUName = StringTrimLeft($oldfqdn, StringInStr($oldfqdn, "OU=") - 1)
    
    $obj_OU = _ADObjGet("LDAP://" & $strHostServer & "/" & $OUName)
    If IsObj($obj_OU) Then
        $newdisplayname = StringReplace($newdisplayname, ",", "\,")
        $obj_OU.MoveHere("LDAP://" & $oldfqdn, "CN=" & $newdisplayname)
        Return 0
    Else
        SetError(1)
        Return @error
    EndIf
EndFunc   ;==>_ADRenameObject

I have been playing around with moving computer account and I am having difficulty getting this part working .. I have amended the adfunctions rename function to look like this

[/code]


 _ADRenameObject
; Takes a FQDN of an Object and a new Display name.
; Renames the object.
; Returns 0 for success, 1 if the OU object was not found.
Func _ADRenameObject($oldfqdn, $newfqdn, $asset)
    $OUName = StringTrimLeft($oldfqdn, StringInStr($oldfqdn, "OU=") - 1)
    msgbox(0, "Adfunctions", $OUName)
    $obj_OU = _ADObjGet("LDAP://" & $strHostServer & "/" & $OUName)
    If IsObj($obj_OU) Then
    ;$assettag = StringReplace($assettag, ",", "\,")
        
        $obj_OU.MoveHere("LDAP://" & $Newfqdn, "CN=" & $asset)
        Return 0
    Else
        SetError(1)
        Return @error
    EndIf
EndFunc  ;==>_ADRenameObject
I have then ran my script which returns with no error but does not move the computer account

My Script :
#include <AdFunctions.au3>#include <array.au3>$asset = "cmplap"dim $oldfqdn = "ou=unassigned,ou=active,ou=Allcomputers,DC=MYDOM,DC=co,DC=uk" dim $newfqdn = "ou=Site1,ou=active,ou=Allcomputers,DC=MYDOM,DC=co,DC=uk" _ADRenameObject($oldfqdn, $newfqdn, $asset)



			
		

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
×
×
  • Create New...