Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to create a script that will enable our automated tool to add certain groups into the localgroups of our servers:

net localgroup dbusers aceina\A&H Support (Accenture) /add

The problem I have is that it doesn't seem to like the "&".

C:\Program Files\IBM\SQLLIB\BIN>net localgroup dbusers 'aceina\A&H Support (Accenture)' /add
The syntax of this command is:


NET LOCALGROUP [groupname [/COMMENT:"text"]] [/DOMAIN]
          groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
          groupname name [...] {/ADD | /DELETE} [/DOMAIN]

'H' is not recognized as an internal or external command,
operable program or batch file.

I tried single and double quotes without any success. Can anyone suggest a way to get around this please?

EDIT

Tried:

C:\Program Files\IBM\SQLLIB\BIN>net localgroup dbusers "aceina\A^&H Support (Accenture)" /add
The syntax of this command is:


NET LOCALGROUP [groupname [/COMMENT:"text"]] [/DOMAIN]
          groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
          groupname name [...] {/ADD | /DELETE} [/DOMAIN]

and:

C:\Program Files\IBM\SQLLIB\BIN>net localgroup dbusers 'aceina\A^&H Support (Accenture)' /add
There is no such global user or group: 'aceina\A&H.

System error 1788 has occurred.

The trust relationship between the primary domain and the trusted domain failed.

Thanks

share|improve this question

6 Answers

In the Windows Command Prompt, use ^ to escape characters:

net localgroup dbusers "aceina\A^&H Support (Accenture)" /add
share|improve this answer
If I try that i get the following "The syntax of this command is:.." If I single quote I get "System error 1788 has occurred. The trust relationship between the primary domain and the trusted domain failed". – Jon Jun 8 '09 at 12:57
net localgroup "A&H Support (Accenture)" /add
The command completed successfully.

Worked a charm.

share|improve this answer

I just did the following using CMD.EXE from a Windows XP Professional SP2-based machine that is a member of the "DOMAIN" W2K3 Active Directory domain, logged-on with a user account that has both local "Administrator" and "Domain Admin" rights:

C:\Documents and Settings\EAnderson>net group "A&B Test" /domain /add
The request will be processed at a domain controller for domain ad.tippcity.k12.
oh.us.

The command completed successfully.


C:\Documents and Settings\EAnderson>net localgroup "users" "DOMAIN\A&B Tes
t" /add
The request will be processed at a domain controller for domain ad.tippcity.k12.
oh.us.

The command completed successfully.

Double quotes look fine to me.

share|improve this answer
C:>net localgroup "administrators" "adom\group012345678901234" /add

The command completed sucessfully

C:>net localgroup "administrators" "adom\group0123456789012345" /add

The syntax of this command is:

NET LOCALGROUP
[groupname [/COMMENT:"text"]] [/DOMAIN]
              groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
              groupname name [...] {/ADD | /DELETE} [/DOMAIN]

C:>

Seems net.exe has a problem with long group names. HATE!

share|improve this answer
Wonderful. I just discovered this feature. Looks like net.exe doesn't like usernames that are greater than 25 characters. – splattered bits Dec 22 '10 at 22:00

I know it sounds crazy, but it's actually because of the length of the group name, not because it has a space. That's why the other people responded saying it worked for them (because the group names they tried weren't as long). I was having the same problem you were, but I found out it was because of the long group name that the "net" command wasn't handling properly. Then I found a utility called "lg" from joeware.net. It worked like a champ. Hopefully this info will help someone else who stumbles on this issue.

share|improve this answer

You’ll notice that if you use a “net localgroup administrators /add DOMAIN\Group” that the command fails with a syntax error. Some folks say that this is because of a limitation on the length of the group name, but I call shenanigans on that explanation. At any rate, you’ll slam your head against your desk for a while, until you do the following:

1) Open up Notepad

2) Paste in the following lines, substituting [DOMAINNAME] and [DOMAINGROUPNAME] as necessary:

Set objLocalGroup = GetObject("WinNT://./Administrators")

Set objADGroup1 = GetObject("WinNT://DOMAINNAME/DOMAINGROUPNAME")

objLocalGroup.Add(objADGroup1.ADsPath)

Set objLocalGroup = Nothing

Set objADGroup = Nothing

3) Go to File > Save As, and save it on your Desktop as “script.vbs”

4) Go to Start and type in cmd, then right-click on cmd and choose “Run as Administrator”:

5) CD to your Desktop and then run the command: “cscript script.vbs” as in the example below, and once the script runs, do a “net localgroup administrators” to verify that the script added the requested group properly:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.