Page 1 of 1 1
Topic Options
#114691 - 2004-02-24 03:50 PM Rename Global Groups
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Is there a script to rename global groups in an active directory (both AD-Groupname and Pre-Windows2000-Groupname)?
_________________________
Jens Kalski

Top
#114692 - 2004-02-24 08:12 PM Re: Rename Global Groups
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
It is pretty straight forward.

Bind to the parent container of the group.
Lookup the MOVEHERE method. You must use the MOVEHERE method to rename an AD object.
Bind to the group and set the sAMAccountName to the new name.
Setinfo

I may pull out the silver platter if I get time this evening.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#114693 - 2004-02-25 05:46 AM Re: Rename Global Groups
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Take a look at this. The code has been tested using a "Domain Local" group on my W2K active Directory domain and verified via "Active Directory Users and Computers".

The input parameters have been tested using the NetBIOS domain name and the NT4 samaccountname. This UDF will work with users, computers, and groups. It will not work with OUs as they do not have an equivelent NT4 name (sAMAccountName property).

Code:
Function RenameADobject ($Domain, $OldSamName, $NewSamName)

Dim $DN, $NameTranslate, $oDN, $rc
$NameTranslate = CREATEOBJECT ("NameTranslate")
if @Error = 0
$NameTranslate.Init (1, $Domain)
if @Error = 0
$NameTranslate.Set (3, $Domain + "\" + $OldSamName)
if @Error = 0
$DN = $NameTranslate.Get(1)
if @Error <> 0
;Writelog("RenameADobject: NameTranslate Get error " + @error + " " + @serror)
Exit @error
endif
else
;Writelog("RenameADobject: NameTranslate Set error " + @error + " " + @serror)
Exit @error
endif
else
;Writelog("RenameADobject: Init NameTranslate error " + @error + " " + @serror)
Exit @error
endif
else
;Writelog("RenameADobject: NameTranslate CreateObject error " + @error + " " + @serror)
Exit @error
endif

$oDN = GetObject("LDAP://$Domain/" + $DN)
$Parent = $oDN.Parent
$oDN.sAMAccountName = $NewSamName
$oDN.SetInfo
if @Error <> 0
Exit @error
endif

$oParent = GetObject($Parent)
$oDN = $oParent.MoveHere("LDAP://" + $DN, "CN=" + $NewSamName)
Exit @error
Endfunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#114694 - 2004-02-25 07:55 AM Re: Rename Global Groups
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Not sure this has to be done with Sam name does it Howard?

Have not reviewed all the details, but samples I've seen don't seem to use the Sam name for the rename so long file names should still be supported just as if you were doing with the GUI.

Top
#114695 - 2004-02-25 01:23 PM Re: Rename Global Groups
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This UDF is limited to security objects. The request was to rename global groups. So I wrote some that would rename anything that could be referred to as Domain\UserName or Domain\GroupName. I find that refferring to these types of objects by the NT4 style name to be easier and more convenient than the FQDN.


That being said any AD object can be renamed using the MOVEHERE method. You just need to supply the complete DN or GUID of the object to be renamed then lookup the parent and perform the last couple lines of the UDF.

I knocked this out quickly. More time could be spent making it more generic so that it supports the renaming of any object.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#114696 - 2004-02-27 03:39 PM Re: Rename Global Groups
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Thanks a lot for the script!
_________________________
Jens Kalski

Top
#114697 - 2004-02-27 10:59 PM Re: Rename Global Groups
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Let me know if it works adequately for you.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#114698 - 2004-02-28 05:28 PM Re: Rename Global Groups
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
I'll test it on monday.
_________________________
Jens Kalski

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2870 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org