Change properties of Local Group; e.g. rename group, change description.

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
GlennXS
Posts: 5
Last visit: Tue Aug 08, 2017 7:27 pm

Change properties of Local Group; e.g. rename group, change description.

Post by GlennXS »

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"


It 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/s ... 61f5bb856c


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

Thanks,
GlennXS
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Change properties of Local Group; e.g. rename group, change description.

Post by jvierra »

This is how to rename a group:

'sGroup.Rename(“Gusto”)
User avatar
GlennXS
Posts: 5
Last visit: Tue Aug 08, 2017 7:27 pm

Re: Change properties of Local Group; e.g. rename group, change description.

Post by GlennXS »

I tried that, however, i'll go back and try it again. Thanks for the immediate reply ... :)
User avatar
GlennXS
Posts: 5
Last visit: Tue Aug 08, 2017 7:27 pm

Re: Change properties of Local Group; e.g. rename group, change description.

Post by GlennXS »

In the meanwhile, I'm also trying to change the description; e.g. sGroup.Description = "Gusto privileges"

... do you think this should work also; maybe sGroup.Description( "Gusto privileges")?
User avatar
GlennXS
Posts: 5
Last visit: Tue Aug 08, 2017 7:27 pm

Re: Change properties of Local Group; e.g. rename group, change description.

Post by GlennXS »

Thought I did this before but I tried again using the () syntax (just to be sure); doesn't work. The error msg is:

Error: Object doesn't support this property or method: 'sGroup.Rename'
Code: 800A01B6
Source: Microsoft VBScript runtime error

Should I be using WinMgmt namespace instead of WinNT ? ...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Change properties of Local Group; e.g. rename group, change description.

Post by jvierra »

Sorry. With VBScript we need to use
Set Newobject = computer.MoveHere(object,"Newname")
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Change properties of Local Group; e.g. rename group, change description.

Post by jvierra »

Code: Select all

Set oGroup = GetObject( "WinNT://alpha/TestGrp, group")
Set oComputer = GetObject( "WinNT://alpha")
Set oNewGroup = oComputer.MoveHere(oGroup.aDSPath, "NewTestGrp")
WScript.Echo oNewGroup.aDSPath
User avatar
GlennXS
Posts: 5
Last visit: Tue Aug 08, 2017 7:27 pm

Re: Change properties of Local Group; e.g. rename group, change description.

Post by GlennXS »

Thanks!!!
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked