none
Change properties in Local Group; e.g. rename group, change description. RRS feed

  • Question

  • While instantiating a Windows system (server 2012r2) from a virtual image template (Hypervisor, vmWare) that has much software preinstalled, I have a vbScript to reconfigure the instantiated image based on its new computer name; e.g. customer joins it to their domain (changes the machine name).  To minimize the end user's work, the script reconfigures a ~dozen properties, adds some user groups, and so on; the end user only specifies a few parameters to the script. The script is fine except i can't figure out how to rename a few local user groups and change the Group's Description; i need help here.

    My first attempt (in simple form) went this way ...

    Set sGroup = GetObject( "WinNT://./Administrator, group")
    sGroup.Name = “Gusto”
    'sGroup.Rename = “Gusto”
    'sGroup.FullName = “Gusto”
    sGroup.SetInfo
    

    The script errors (438) upon the sGroup.Name statement; i tried the commented statements too but get the same error.  Then, i referred to the Ms>Docs>ADSI WinNT objects > ... documentation and came up with a documented method ...


        sGroup.Put "Name", "Gusto"


    The put statement crashed too but with a different error; 8000500F

    I believe the Put method is the way to go, however, i think i have to add something like ..    .           

        oName = sGroup.Get( "Name")


    ... and apply this somehow ...  I got this idea from ...


        https://gallery.technet.microsoft.com/scriptcenter/10dae29d-5d1d-44d8-9462-4d61f5bb856c


    So, i need to rename a few groups and change their Description properties.  Can somebody help me with this?

    Thanks,
    GlennXS



    Glenn of xSyLent

    Monday, July 24, 2017 3:50 AM

Answers

  • Nice; it works in the short & sweet form ...

    function renGroup(oName, nName)
      renGroup =  false
      Set oComputer = GetObject( "WinNT://.")
      Set sGroup = GetObject( "WinNT://./" & oName & ", group")
      oComputer.MoveHere sGroup.ADsPath, nName
      if err.number = 0 then renGroup3 =  true
    end function

    ... just peachy!!!  thanks Richard!


    Glenn of xSyLent


    • Edited by GlennXS Wednesday, July 26, 2017 8:35 PM cleanup
    • Marked as answer by Bill_StewartModerator Wednesday, September 13, 2017 9:13 PM
    Wednesday, July 26, 2017 8:32 PM

All replies

  • sGroup.Rename("NewName")

    I recommend that you learn how to write a script and use PowerShell.  VBScript is pretty much obsolete and will not be of much use in th efuture.


    \_(ツ)_/

    Monday, July 24, 2017 8:34 AM
  • I appreciate that; wish I knew 4 weeks ago.  In the meanwhile, I suspect the solution is do-able as the vbScript I have does so much as it is; this is all that's holding me back from finishing it.  I would sincerely appreciate some contributions from those with abilities/expertise in manipulating these put() & setinfo() methods.

    Glenn of xSyLent

    Monday, July 24, 2017 1:28 PM
  • It works the same way in VBScript.

    \_(ツ)_/

    Monday, July 24, 2017 4:52 PM
  • The Name property exposed by the WinNT provider retrieves the sAMAccountName. There is no Rename method. Instead use the MoveHere method of the container object (computer or domain). For example:

    objComputer.MoveHere objUser.ADsPath, strNewName

    where objComputer is the computer or domain, objUser is the user object (bound using WinNT), and strNewName is the new name. Documentation on the MoveHere method:

    https://msdn.microsoft.com/en-us/library/aa705991%28v=vs.85%29.aspx


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Monday, July 24, 2017 7:35 PM
    Moderator
  • Thanks so much Richard; I recognize your name; it reverberates across this arena!!!  I'm about to head out for the day but will get into this from home; i'll keep u posted but I expect it to work.


    Glenn of xSyLent

    Monday, July 24, 2017 9:10 PM
  • I should add, when you update properties, the change is made to the copy of the object in local memory, so you must invoke the SetInfo method to write the object back to AD. But the methods SetPassword and MoveHere are immediate, so SetInfo is not required. Also MoveHere, besides able to move objects, modifies the RDN of AD objects, so the new name should be in the form "cn=Jim Smith", where "Jim Smith" is the new value of the cn attribute (and of course the same for groups). You need to include the "cn=" moniker.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Monday, July 24, 2017 10:33 PM
    Moderator
  • Nice; it works in the short & sweet form ...

    function renGroup(oName, nName)
      renGroup =  false
      Set oComputer = GetObject( "WinNT://.")
      Set sGroup = GetObject( "WinNT://./" & oName & ", group")
      oComputer.MoveHere sGroup.ADsPath, nName
      if err.number = 0 then renGroup3 =  true
    end function

    ... just peachy!!!  thanks Richard!


    Glenn of xSyLent


    • Edited by GlennXS Wednesday, July 26, 2017 8:35 PM cleanup
    • Marked as answer by Bill_StewartModerator Wednesday, September 13, 2017 9:13 PM
    Wednesday, July 26, 2017 8:32 PM