Sample scripts for dsadd, dsmodify, dsget, dsquery, dsmod, dsmove


Following my Technet session on the New Features of Windows Server 2003 Active Directory, scenario based, here’s the scripts which I promised to post up. Hope they are useful. Even if you didn’t attend the session, they give you a good example of how these command line programs can be used. Remember that the Windows Server Help and Support has very detailed information on the parameters to these commands – often overlooked when people head straight over to their favourite Internet search engine….

AddUsers.bat

dsadd ou “OU=Sales,DC=worldwideimporters,DC=com”
dsadd ou “OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd user “CN=KimA,OU=Sales,DC=worldwideimporters,DC=com”
dsadd user “CN=SeanA,Ou=Sales,DC=worldwideimporters,DC=com”
dsadd user “CN=NeilC,Ou=Sales,DC=worldwideimporters,DC=com”
dsadd user “CN=AaronC,Ou=Sales,DC=worldwideimporters,DC=com”
dsadd user “CN=AndrewH,Ou=Sales,DC=worldwideimporters,DC=com”
dsadd user “CN=DonH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd user “Cn=GarthF,Ou=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd user “CN=MarkH,Ou=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd user “CN=JoB,Ou=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd user “CN=ScottC,Ou=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd group “CN=Sales Users,CN=users,DC=worldwideimporters,DC=com” -scope g
dsadd group “CN=Marketing and Finance Users,CN=users,DC=worldwideimporters,DC=com” -scope g
dsadd group “CN=Sales Data,CN=users,DC=worldwideimporters,DC=com” -scope l
dsadd group “CN=Marketing and Finance Data,CN=users,DC=worldwideimporters,DC=com” -scope l
dsadd computer “CN=SALESWKSTN1,OU=Sales,DC=worldwideimporters,DC=com”
dsadd computer “CN=SALESWKSTN2,OU=Sales,DC=worldwideimporters,DC=com”
dsadd computer “CN=MAFWKSTN1,OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsadd computer “CN=MAFWKSTN2,OU=Marketing and Finance,DC=worldwideimporters,DC=com”

ModifyMembers.bat

dsmod group “CN=Marketing and Finance users,CN=users,DC=worldwideimporters,DC=com” -addmbr “CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com” “CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com” “CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsmod user “CN=KimA,OU=Marketing and Finance,DC=worldwideimporters,Dc=com” “CN=SeanA,OU=Marketing and Finance,DC=worldwideimporters,DC=com” “CN=AaronC,OU=Marketing and Finance,DC=worldwideimporters,DC=com” -pwd Abcd123 -mustchpwd yes

MoveUsers.bat

dsmove “CN=KimA,OU=Sales,DC=worldwideimporters,DC=com” -newparent “OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsmove “CN=AaronC,OU=Sales,DC=worldwideimporters,DC=com” -newparent “OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsmove “CN=SeanA,OU=Sales,DC=worldwideimporters,DC=com” -newparent “OU=Marketing and Finance,DC=worldwideimporters,DC=com”ModifyMembers.bat

QueryUsers.bat

dsget user “CN=KimA,OU=Sales,DC=worldwideimporters,DC=Com” -memberof -expand >”c:documents and SettingsAll UsersDesktopuserinfo.txt”
dsquery user “OU=Sales,DC=worldwideimporters,DC=com” >>”c:documents and SettingsAll UsersDesktopuserinfo.txt”
dsquery user “OU=Marketing and Finance,DC=worldwideimporters,DC=com” >>”c:documents and SettingsAll UsersDesktopuserinfo.txt”
Notepad “c:documents and SettingsAll UsersDesktopuserinfo.txt”

Remove1.bat

dsrm -noprompt -c “cn=KimA,OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsrm -noprompt -c “CN=mafwkstn1,OU=Marketing and Finance,DC=worldwideimporters,DC=com”
dsrm -noprompt -c “CN=Marketing and Finance Users,CN=Users,DC=worldwideimporters,DC=com”
dsrm -subtree -noprompt -c “OU=Marketing and Finance,DC=worldwideimporters,DC=com”

RemoveAll.bat

dsrm -subtree -noprompt -c “OU=Sales,DC=worldwideimporters,DC=com”
dsrm -noprompt -c “CN=Marketing and Finance Data,CN=Users,DC=worldwideimporters,DC=com”
dsrm -noprompt -c “CN=Sales Users,CN=Users,DC=worldwideimporters,DC=com”
dsrm -noprompt -c “CN=Sales data,CN=Users,DC=worldwideimporters,DC=com”

Comments (1)

  1. Luc Geurts says:

    Thanks for the scripts. Gonna use them ASAP. Luc.