When trying to add a global group with a name longer than 20 characters using net.exe
I get an error saying that the syntax is incorrect, as follows:
C:\>NET.EXE localgroup MyRemoteUsers "really-long-group-name-here" /ADD
The syntax of this command is:
NET LOCALGROUP [groupname [/COMMENT:"text"]] [/DOMAIN]
groupname {/ADD [/COMMENT:"text"] | /DELETE} [/DOMAIN]
groupname name [...] {/ADD | /DELETE} [/DOMAIN]
This problem is documented by Microsoft here. I need this to work inside a standard .cmd batch file. Is there a simple workaround?
In this article To run net localgroup, open a command prompt, type net localgroup with the appropriate parameters, and then press ENTER.
Press the Windows key + R to open the Run dialog box, or open the Command Prompt. Next type lusmgr. msc and hit Enter. This will open the Local Users and Groups snap-in directly.
You can use powershell in a batch file like this:
powershell -command "& { ([adsi]'WinNT://./your-local-group,group').Add('WinNT://YOURDOMAIN/your-really-long-global-group-name,group'); }"
One of the tricks above is to use double quotes for entire command while using single quotes within the commands. This allows you to run the statement from cmd.exe
or inside a .bat/.cmd file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With