We want to easily create a large number of guest accounts with minimal interaction.  Everything works good except one problem...
I don't want the guest to be part of "Domain Users", which is added by default to new accounts, but I can't remove it with dsmod because it says "can't remove the primary group".  Is there some sort of code/script that I can add to this to basically change the primary group from Domain Users to Guest once the account is created?
 
FOR /L %i in (1,1,10) DO dsadd user "cn=CCU Guest%i,ou=Custom Object,dc=my,dc=domain,dc=edu" -samid CCUGuest%i -fn CCU -ln Guest%i -display "CCU Guest%i" -pwd g5%i2%i9 -disabled no -memberof "CN=Guest,CN=Users,DC=my,DC=domain,DC=edu" "CN=Domain Guests,CN=Users,DC=my,DC=domain,DC=edu"
 
dsmod group "CN=Domain Users,CN=Users,DC=my,DC=domain,DC=edu" -rmmbr "CN=CCU Guest1,OU=Custom Object,DC=my,DC=domain,DC=edu"
We want to easily create a large number of guest accounts with minimal interaction.  Everything works good except one problem...
I don't want the guest to be part of "Domain Users", which is added by default to new accounts, but I can't remove it with dsmod because it says "can't remove the primary group".  Is there some sort of code/script that I can add to this to basically change the primary group from Domain Users to Guest once the account is created?
 
FOR /L %i in (1,1,10) DO dsadd user "cn=CCU Guest%i,ou=Custom Object,dc=my,dc=domain,dc=edu" -samid CCUGuest%i -fn CCU -ln Guest%i -display "CCU Guest%i" -pwd g5%i2%i9 -disabled no -memberof "CN=Guest,CN=Users,DC=my,DC=domain,DC=edu" "CN=Domain Guests,CN=Users,DC=my,DC=domain,DC=edu"
 
dsmod group "CN=Domain Users,CN=Users,DC=my,DC=domain,DC=edu" -rmmbr "CN=CCU Guest1,OU=Custom Object,DC=my,DC=domain,DC=edu"

What do you want the guest user accounts to be a part of? I they are a part of anything else they will have more privilages! It sounds like your trying to create a new domain group. If you are, just create your new group and add you guest account to that group. Then remove the guest account from the domain users group. You should be able to do this in computer management.

We already have guest groups created. The problem is that we want to script it so we can create 500 guest accounts in a matter of minutes. My script adds people to the two guest groups but I can't remove them from the default "Domain Users" which is assigned by default when the accounts are created. I get the error, "can't remove the primary group assigned", so I am looking for script similar to what I posted that would modify what the primary memberOf group is so that Domain Users can be removed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.