How to add a group with a long name to a local group from the command line or batch file?

When I try to add a global group with a name longer than 20 characters using net.exeI get an error that the syntax is incorrect:

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 described by Microsoft here . I need this to work in a standard .cmd batch file. Is there an easy way?

+5
source share
1 answer

You can use powershell in a batch file as follows:

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 the entire command when using single quotes in commands. This allows you to run the statement from cmd.exeor inside the .bat / .cmd file.

+7
source

All Articles