Home Microsoft Windows Server 2008 and Server 2008 R2
Example DSADD, DSMOD, DSGET, DSQUERY. DSMOVE and DSRM commands Print E-mail

 

Reset Password and Force Change at Logon for an Entire OU:

dsquery user "OU=London,OU=Staff,DC=vmadmin,DC=local" | dsmod user -pwd Password1 -mustchpwd yes

 

 

Change "company" AD attribute for all Users in an Entire OU:

dsquery user "OU=London,OU=Staff,DC=vmadmin,DC=local" | dsmod user -company "VMadmin"

 

 

 
Return the DN of all users in an OU:
dsquery user "OU=London,OU=Staff,DC=vmadmin,DC=local"

 

"CN=User1,OU=London,OU=Staff,DC=vmadmin,DC=local"
"CN=User2,OU=London,OU=Staff,DC=vmadmin,DC=local"
"CN=User3,OU=London,OU=Staff,DC=vmadmin,DC=local"
  
 


Return the DN of all users in an OU, then get all the groups the users are a member of:
dsquery user "OU=London,OU=Groups,DC=vmadmin,DC=local" | dsget user -memberof
 
"CN=Group1,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group2,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group3,OU=London,OU=Groups,DC=vmadmin,DC=local"

 

 


Return the DN of all users in an OU, then get all the groups the users are a member of and use recursion:
dsquery user "OU=London,OU=Staff,DC=vmadmin,DC=local" | dsget user -memberof -expand
 
"CN=Group1,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group2,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group3,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group4,OU=London,OU=Groups,DC=vmadmin,DC=local"
"CN=Group5,OU=London,OU=Groups,DC=vmadmin,DC=local"

 
 


Return the DN of all users in an OU, then get all the groups the users are a member of and use recursion. Then return the name of all the groups:
dsquery user "OU=London,OU=Staff,DC=vmadmin,DC=local" | dsget user -memberof -expand | dsget group -samid

 

  samid
  Group1
  Group2
  Group3
  Group4
  Group5
 
 
 
Get all the groups a user is a member of and use recursion. Then return the name of all the groups:
dsquery user "CN=User3,OU=London,OU=Staff,DC=vmadmin,DC=local" | dsget user -memberof -expand | dsget group -samid

 

  samid
  Group1
  Group2

 

 

 

 

Create an OU:

dsadd ou "ou=London,dc=domain,dc=local"

 

Create a Group:

dsadd group "cn=London Users,ou=London,dc=domain,dc=local"

 

Create a User:
dsadd user "cn=JoeUser1,ou=London,dc=domain,dc=local"

 

Add a User to a Group:

dsmod group "cn=LondonUsers,ou=London,dc=domain,dc=local" -addmbr "cn=JoeUser1,ou=London,dc=domain,dc=local"

 

Find User Beggining with "J" and Return Matching Users "samid" and "department" Attributes:

dsquery user domainroot -name J* | dsget user -samid -dept

 

Move an OU:

dsmove "ou=LiverpoolStreetOffice,dc=domain,dc=local" -newparent "ou=London,dc=domain,dc=local"

 

Rename and OU:
dsmove "cn=LondonUsers,ou=London,dc=domain,dc=local" -newname LondonStaff

 

Remove an OU and all its Subtree Without Prompting:

dsrm -noprompt -subtree "ou=deleteme,dc=domain,dc=local"

 

 

 

 

 

 

 

        
            

      

 

DISCLAIMER: All advice, tips, guides and other information on this website is provided as-is with no warranty or guarantee. While most information is correct to the best of my knowledge, I am not reponsible for any issues that may arise in using the information, and you do so at your own risk. As always before doing anything; check, double check, test and always make a backup.

 

Help VMadmin

All resources on this site are provided absolutley free. However it takes time and money to keep the site running. If any information has been helpful to you or your company, and you wish to make a donation to help keep VMadmin.co.uk running you can do so via paypal, and it would be much appreciated.

Click to donate to VMadmin.co.uk via paypal.