deeejay

dsquery commands for AD

Jun 11th, 2014 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.05 KB | None | 0 0
  1. dsget user <UserDN> [-dn] [-samid] [-sid] [-upn] [-fn] [-mi] [-ln] [-display] [-empid] [-desc] [-office] [-tel] [-email] [-hometel] [-pager] [-mobile] [-fax] [-iptel] [-webpg] [-title] [-dept] [-company] [-mgr] [-hmdir] [-hmdrv] [-profile] [-loscr] [-mustchpwd] [-canchpwd] [-pwdneverexpires] [-disabled] [-acctexpires] [-reversiblepwd] [{-uc | -uco | -uci}] [-part <PartitionDN> [-qlimit] [-qused]]
  2. dsget user <UserDN> [-memberof] [-expand][{-uc | -uco | -uci}]
  3.  
  4. Other sources:
  5. http://nickbeare.com/ad_cmd.html
  6.  
  7. Note: You can use these command line utilities after installing the AdminPak or simply copying the DS *.exe files to your computer. Suggest adding path to files to environment variables for quick access via command prompt.
  8.  
  9. IMPORTANT: Starting with Windows 10 October 2018 Update, add RSAT tools right from Windows 10. Just go to "Manage optional features" in Settings and click "Add a feature" to see the list of available RSAT tools.
  10.  
  11. User Commands
  12. List user's DN
  13. dsquery user -name someuser
  14.  
  15. List user's memberships
  16. dsquery user -name someuser | dsget user -memberof -expand
  17.  
  18. List user's first name, last name, and title
  19. dsquery user -name someuser | dsget user -samid -fn -ln -title
  20.  
  21. List user's telephone number
  22. dsquery user -name someuser | dsget user -tel
  23.  
  24. List user's fax number
  25. dsquery user -name someuser | dsget user -fax
  26.  
  27. List user's email
  28. dsquery user -name someuser | dsget user -email
  29.  
  30. List user's title
  31. dsquery user -name someuser | dsget user -title
  32.  
  33. List all disabled users
  34. dsquery user "OU=someou,OU=anotherou,dc=somedomain,dc=org" -disabled
  35.  
  36. Check if a user is disabled
  37. dsquery user -name someuser -disabled
  38.  
  39. Note: If the user is disabled, his/her DN will be displayed
  40. List user's mailbox
  41. dsquery * -filter "samaccountname=someuser" -attr homemdb
  42.  
  43. List all members in OU
  44. dsquery user "OU=someou,OU=anotherou,dc=somedomain,dc=org"
  45.  
  46. Export user attributes (Takes a while to run - Press Ctrl+C to quit)
  47. dsquery * -limit 0 -filter "&(objectClass=User)(objectCategory=Person)" -attr * >> c:\output.txt
  48.  
  49. List all users with "Director" in the title attribute (limit to 150 results)
  50. dsquery * "OU=someou,OU=anotherou,dc=somedomain,DC=ORG" -filter "(&(objectCategory=Person)(objectCategory=User)(title=*Director*))" -attr name title -limit 150
  51.  
  52. Search for a user by first name
  53. dsquery * -filter "(&(objectCategory=Person)(objectClass=User)(givenName=John*))" | dsget user -fn -ln -samid -title
  54.  
  55.  
  56. Computer Commands
  57.  
  58. List computer's DN
  59. dsquery computer -name somedevice
  60.  
  61. List multiple computer's DNs
  62. dsquery computer -name somedevice*
  63.  
  64. List computer's memberships
  65. dsquery computer -name somedevice | dsget computer -memberof -expand
  66.  
  67. List computers with Windows XP Computers with Service Pack 2 Installed
  68. dsquery * "OU=someou,OU=anotherou,dc=somedomain,dc=org" -filter "(&(objectCategory=computer)(operatingSystem=Windows XP Professional)(operatingSystemServicePack=Service Pack 2))"
  69.  
  70. List enabled computer accounts in OU
  71. dsquery computer "OU=someou,OU=anotherou,dc=somedomain,dc=org" -limit 5000 | dsget computer -dn -disabled | find /c /i " no"
  72.  
  73. Reset a computer account
  74. dsmod computer "cn=somedevice,ou=Laptops,ou=Computers,OU=someou,OU=anotherou,dc=somedomain,DC=org" -reset
  75.  
  76.  
  77. Group Commands
  78.  
  79. List all   security groups that begin with GPO-15
  80. dsquery group -name GPO-15*
  81.  
  82. List security groups with a partial name
  83. dsquery group -name SomeName*File*
  84.  
  85.  
  86. Admin Commands
  87.  
  88. List all AD Servers
  89. dsquery server
  90.  
  91. List all DNs
  92. dsquery partitions
  93.  
  94.  
  95. Group Commands
  96.  
  97. Wildcard search for all groups beginning with 10_PIC
  98. dsquery group -name 10_PIC*
  99.  
  100. Export member DNs of a specified group
  101. dsget group "CN= -DragonVoiceProfiles Group,OU=Security Groups,OU=Groups,OU=someou,OU=anotherou,dc=somedomain,DC=org" -members >> sb.txt
  102.  
  103. Export username, firstname, lastname, title, department for members of a specified group (use -c to continue exporting if errors are found, i.e. device user accounts)
  104. dsquery group -name 10_PICPOwerChart | dsget group -members -expand -c | dsget user -samid -fn -ln -title -dept -c >> 10_PICPOWERCHART.txt
  105.  
  106. List firstname, lastname, title from a specified group
  107. dsquery group -name "AH Azure DNA Dev Team" | dsget group -members | dsget user -fn -ln -title
  108.  
  109. Count from list above but subtract 2 for header line and "dsget succeeded" line
  110. dsquery group -name "AH Azure DNA Dev Team" | dsget group -members | dsget user -fn -ln -title | find /c /v ""
  111.  
  112. Display each group and respective members in each group
  113. for /f "delims=" %G in ('dsquery group -name "Operational Finance PowerBI*"') do (
  114.     echo Group: %G
  115.     dsget group %G -members
  116. )
  117.  
  118. for /f "delims=" %G in ('dsquery group -name "AH Azure*"') do (
  119.     echo Group: %G
  120.     dsget group %G -members
  121. )
  122.  
  123.  
  124. for /f "delims=" %G in ('dsquery group -name "AH Azure*"') do (
  125.     for /f "tokens=2 delims==," %H in ('echo %G') do (
  126.         echo Processing group: %H
  127.         dsget group %G -members > "%H.txt"
  128.     )
  129. )
  130.  
  131.  
  132.  
  133. Find user in domain by SID
  134. dsquery user "dc=your_domain,dc=org" | dsget user -samid -sid | find "S-1-5-21-1960408961-823518204-839522115-97681"
Advertisement
Add Comment
Please, Sign In to add comment