Active Directory-- DSQUERY Commands

Active Directory: DSQUERY Commands

DSQUERY Commands to query AD objects:-

1. How to find all members for a particular group.    
  dsget group "<DN of the group>" -members

1a. How to find all groups for a particular member (including nested groups)    
  dsget user "<DN of the user>" -memberof -expand 
  dsquery user -samid "username" | dsget user -memberof -expand    
2. How to find memberof , lastlogontimestamp , homemta(Mail server) , Samaccountname & so on(Repadmin /showattr <DCname> <"DN">)

dsquery * "<DN>" -scope base -attr lastlogontimestamp memberoff 
repadmin /showattr <DCNAME> <"DN"> /attrs:lastlogon,homemta,whencreated,lastlogontimestamp,samaccountname

3. How to modify user last name.

dsmod user <dn> -ln "<last name>"

4. How to find memberof , lastlogontimestamp , homemta(Mail server) , Samaccountname & so on for "n" number of users

Create a batch file(for /f "eol= tokens=* delims= usebackq" %%x in (%1) do dsquery * %%x -scope base -attr sAMAccountName objectsid whencreated  lastlogontimestamp mail homeMTA memberof) e.g ds.bat 
Create a text file (All users DN e.g:dn.txt)    
Open cmd & run ds.bat dn.txt >> c:\attr.txt

5. How to find DN for n number of computers

for /f %%x in (%1) do dsquery computer -name %%x  
  (Create a batch file with line & create a txt file computer.txt    
  open cmd >>>>>>batchfile computer.txt >> c:\dn.txt

6. Find Subnet with associated site.    
  dsquery subnet -name <CIDR> | dsget subnet 
8.How to find disabled users    
  dsquery user "dc=ssig,dc=com" -disabled 
  dsquery * -filter "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))" 
9. How to find OS?    
dsquery * <"DN"> -scope base -attr operatingSystem 
10. How to find site ?

dsquery site -name * -limit 0

dsquery server -s <server> | dsget server -site  
11. How to get tombstonelifetime ?

dsquery * "CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=yourdomain,DC=com" -scope base -attr tombstonelifetime  
13. How to find mail box?    
dsquery * -filter "samaccountname=biswajit" -attr homemdb   
14. How to find the GCs?

DsQuery Server -domain contoso.com -isgc

15.How to find all the active users?    
dsquery * -filter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))"

16.How to find users logon name by their mail address for bulk users?    
For Single user    
  dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(mail=e-mailaddress))" -attr name    
  For bulk users    
  for /f %%x in (%1) do dsquery * domainroot -filter "(&(objectcategory=person)(objectclass=user)(mail=%%x))" -attr name    
17. How to find Schema version?      
  dsquery * cn=schema,cn=configuration,dc=domainname,dc=local -scope base -attr objectVersion 
  or    
schupgr    
   
Shortest command for finding the schema version      
   
18. How to find Site name by server name ?    
  dsquery server -name test1 | dsget server -site 
  dsquery server -name (provide the server name for DN) | dsget server -site

19. How to find all groups of a user is memberof without the DN‘s?    
  dsquery user -samid anthony | dsget user -memberof | dsget group -samid 
  dsquery user -samid (provide the samaccount name of the user) | dsget user -memberof | dsget group -samid 
20. How to find all groups if a computer account without giving the DN‘s ? 
  dsquery computer -name test1 | dsget computer -memberof | dsget group -samid 
21. How to find PDC role holder for the existing domain ?    
  dsquery server -hasfsmo PDC    
22. How to find Infrastructure Master role holder existing domain ?    
  dsquery server -hasfsmo INFR    
23. How to find RID master role holder for existing domain ?    
  dsquery server -hasfsmo RID    
24. How to find Schema master role holder in a Forest ?    
  dsquery server -forest -hasfsmo Schema 
25. How to find Domain Naming Master in a Forest ? 
  dsquery server -forest -hasfsmo Name 
26. How to find if the Domain Controller is a Global Catalog (GC) or not ?    
  dsquery server -name test1 | dsget server -isgc    
27. How to find subnet with associated site.    
  dsquery subnet -name 10.222.88.0/25 | dsget subnet

28.  How to find SID of a user?    
  dsquery user -samid <bbiswas> | dsget user -sid    
  dsquery * -filter (samaccountname=santhosh) – attr sid 
29.  How to find sIDHisotry of a user?    
  Dsquery * -filter (samaccoutname=santhosh) – attr siDhistory  
30.  How to find enabled computer accounts in an OU?    
dsquery computer OU=Test,DC=sivarajan,DC=com -limit 5000 | dsget computer -dn -disabled | find /i " no" 
31.  How to count enabled computer accounts in an OU?    
   
dsquery computer OU=Test,DC=sivarajan,DC=com -limit 5000 | dsget computer -dn -disabled | find /c /i " no"

32. How to find all members for a OU.

dsquery user ou=targetOU,dc=domain,dc=com

33. How to find all groups for a OU.    
dsquery group ou=targetOU,dc=domain,dc=com

34. To get the members status from the active directory group

dsquery group -samid “Group Pre-Win2k Name” | dsget group -members | dsget user -disabled -display

35.Command to find all the subnets for the given site

dsquery subnet -o rdn -site <site name> 
36. Command to find all DCs in the given site    
>>dsquery server -o rdn -site <site name> 
37. Command to find all DCs in the Forest    
   
>>dsquery server -o rdn -forest    
38. To list the distinguished names of all directory partitions in the current forest 
>>dsquery partition 
Below example for single domain    
   
Below example for parent/child domain    
   
39. To find all contacts in the organizational unit (OU)    
dsquery contact OU=Sales,DC=Contoso,DC=Com    
40. To list the relative distinguished names of all sites that are defined in the directory    
dsquery site -limit 0

41. List of all users with primary group "Domain Users"    
dsquery * -filter "(primaryGroupID=513)" -limit 0    
(You can change the "primaryGroupID" as per your requirement)    
513:Domain Users 
514:Domain Guests    
515:Domain Computers    
516:Domain Controllers

42. How to find all attributes for all users?    
   
Dsquery * -limit 0 -filter "&(objectClass=User)(objectCategory=Person)" -attr * >>output123.txt

43. Show How Many Times wrong Password has been entered on a specified domain controller.  
dsquery * -filter "(sAMAccountName=jsmith)" -s MyServer -attr givenName sn badPwdCount    
The badPwdCount attribute is not replicated, so a different value is saved for each user on each domain controller.    
44.Expire use account.    
dsquery * "dc=contoso,dc=com" -filter "(&(objectCategory=Person)(objectClass=User)(!accountExpires=0)(!accountExpires=9223372036854775807)) " -attr sAMAccountname displayName    
Fine Granted Password Policy      
45. How to find the ‘PSO Applies to‘      
i)dsget user <user DN> -effectivepso    
   
Example:

C:\>dsget user "CN=bshwjt,OU=pso,DC=contoso,DC=com" -effectivepso    
effectivepso    
"CN=test,CN=Password Settings Container,CN=System,DC=contoso,DC=com"    
dsget succeeded      
("bshwjt" is the user and test is the "PSO" also see the below snap)    
   
ii) How to find the PSO settings    
C:\>dsquery * "<CN=your pso name>,CN=Password Settings Container,CN=System,DC=contoso,DC=com" -scope base -attr *    
46. Find out Account Expiry date

dsquery user -name * -limit 0 | dsget user -samid -acctexpires  
47.This example displays all attributes of the contoso.com domain object    
dsquery * -filter (dc=contoso) -attr *    
48.This complex example displays the names of all attributes (150) that Windows Server 2003 replicates to Global Catalog servers. (If the command displays no attributes, ensure that you typed TRUE in capital letters    
>dsquery * cn=Schema,cn=Configuration,dc=contoso,dc=com -filter "(&(objectCategory=attributeSchema)(isMemberOfPartialAttributeSet=TRUE))" -limit 0 -attr name    
49. How to get all samaacount name ?    
dsquery user -o rdn -limit 0    
50.The command displays the DNS host name, the site name, and whether the server is Global Catalog (GC) server for each domain controller    
dsquery server | dsget server -dnsname -site -isgc

Get all the servers in the forest    
dsquery server -forest -limit 0 | dsget server -dnsname -site -isgc

51.The dsget command displays properties of users or other objects. In this example, it displays the 6 groups that explicitly list the Administrator as member  
Note: The -memberof -expand combination recursively expands the list of groups of which the user is a member. In this example, the Users group is added to the list because Domain Users is a member of the Users group.    
dsget user cn=Administrator,cn=Users,dc=contoso,dc=com -memberof

52.The output of the dsquery command can be used as input for the dsget command by using a pipe ( | ). In this example, the SAM account name and the security ID (SID) of each user is displayed.  
dsquery user | dsget user -samid -sid -limit 0 >> c:\Allusers-samid-sid.txt    
   
53. How to find RODC ?

dsquery server -isreadonly

Dsqury for exchange server    
54. How to find the Schema Version for Exchange Servers.      
dsquery * CN=ms-Exch-Schema-Version-Pt,cn=schema,cn=configuration,dc=domain,dc=local -scope base -attr rangeUpper      
   
55.How to find lastLogonTimestamp for all users for a domain    
   
dsquery * -filter "&(objectClass=person)(objectCategory=user)" -attr cn lastLogonTimestamp -limit 0    
56. Inactive users are go to disable state

dsquery * <ou> -filter "(&(objectCategory=Person)(objectClass=User)(!accountExpires=0)(!accountExpires=9223372036854775807))" | dsmod user -disabled yes

57.ADDS existing connection point objects

dsquery * forestroot -filter (objectclass=serviceconnectionpoint)  
   
58. Find all Hyper-V hosts in your forest

C:\>dsquery * forestroot -filter "&(cn=Microsoft Hyper-V)(objectCategory=serviceconnectionpoint)" -attr servicebindinginformation >> c:\hyper-v.txt

59. Find all windows virtual machine in your forest

C:\>dsquery * forestroot -filter "&(cn=windows virtual machine)(objectCategory=serviceconnectionpoint)" -limit 0 -attr * >> c:\allvirtualPCs.txt

60.Extract the all groups from an OU with Group Scope & Group Type. Find the below snap for your reference.    
C:\>dsquery group "ou=test,dc=gs,dc=com" -limit 0 | dsget group -samid -scope -secgrp    

61.The below example displays a list of users from the OU "Customer Support",      
can then be forwarded to dsget that can provide detailed information about objects.      
In the example, the requested user list is headed by the pipe symbol after dsget that      
-outputs then the sAMAccountName for all users and email address.      
If we wanted to carry out modifications to the information returned by DSQuery user list,      
we could send the result to dsmod, which for us is making changes to all users.      
In below snap shows the change in the command ensures that all users of DSQuery      
-user list must change their passwords at next logon.

Another way to get the user attributes from an OU. Find the below snap & dsquery for that.  
C:\>dsquery * "ou=test,DC=contoso,DC=com" -filter "(&(objectcategory=person)(objectclass=user))" -limit 0      
-attr samaccountname description department title      

62.retrieve the DN of all users in the domain that are not direct members of a specified group    
>>dsquery * -filter "(&(objectCategory=person)(objectClass=user)(!(memberOf=Groupname,ou=West,    
dc=Contoso,dc=com))) -limit 0 > NotInGroup.txt

63. How to open DSQUERY GUI Window    
rundll32 dsquery,OpenQueryWindow    
DNS application partition      
64. How to find the DNS servers from DomainDNSZones & ForestDNSzones

C:\>dsquery * DC=DomainDnsZones,DC=contoso,DC=com -scope base -attr msDs-masteredBy    
C:\>dsquery * DC=forestDnsZones,DC=contoso,DC=com -scope base -attr msDs-masteredBy    
65.Finding the Functional Levels of Active Directory    
dsquery * "DC=contoso,DC=com" -scope base -attr msDS-Behavior-Version ntMixedDomain

0, 0 Windows 2000 Native domain Level

0, 1 Windows 2000 Mixed domain Level

2, 0 Windows 2003 Domain Level

3, 0 Windows 2008 Domain Level

4, 0 Windows 2008 R2 Domain Level

66. Find the object for DES-Only-Encryption    

dsquery * -filter "(UserAccountControl:1.2.840.113556.1.4.803:=2097152)"

67. Find the DNS servers from all the DNS partitions.    

dsquery * "CN=Configuration,DC=contoso,DC=com" -filter "(&(objectClass=crossRef)(objectCategory=crossRef)(systemFlags=5))" -attr NcName msDS-NC-Replica-Locations

Using LDAP Filter.

68. How to find particular user attribute using LDAP Filter?

C:\>dsquery * -filter (samaccountname=biz) -attr name whenchanged

name    whenchanged

biz     01/03/2014 07:02:14    

69. How to find all disabled users.    

   

PS C:\> dsquery * -filter ("&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2)")

"CN=Guest,CN=Users,DC=Rocky,DC=com"

"CN=krbtgt,CN=Users,DC=Rocky,DC=com"

70. How to find Forestprep , domainprep & RodcPrep is done or not?    

C:\>dsquery * CN=ActiveDirectoryUpdate,CN=ForestUpdates,cn=configuration,dc=msft

,dc=net -scope base -attr revision

  revision

  5

   

C:\>dsquery * CN=ActiveDirectoryRodcUpdate,CN=ForestUpdates,cn=configuration,dc=

msft,dc=net -scope base -attr revision

  revision

  2

命令集合:http://technet.microsoft.com/en-us/library/cc754232(WS.10).aspx

时间: 2024-12-10 17:41:36

Active Directory-- DSQUERY Commands的相关文章

Active Directory participation features and security extensions

Participation in the Active Directory Samba 3.0 series, as well as the OS since Windows 2000, is possible to participate in the Active Directory domain using Kerberos authentication. Because I think people often are interested, let's explain specific

Enabling Active Directory Authentication for VMWare Server running on Linux《转载》

Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breidenbaugh - 2007-06-29 Purpose The purpose of this guide is as follows: Document the steps necessary to enable Active Directory Authentication on a Linu

Winbind authentication against active directory

Winbind authentication against active directory Description This tip will describe how to configure authentication settings in CentOS to use authentication against Windows Servers. I will describe how to do it in a command line. The command line argu

三、 Active Directory 环境部署及验证

Active Directory 安装部署 1. 打开Windows Powershell ,输入如下命令,添加Windows 角色.如图 Add-WindowsFeature  AD-Domain-Services,RSAT-AD-Tools,RSAT-ADDS,RSAT-AD-AdminCenter,RSAT-ADDS-Tools,RSAT-ADLDS,RSAT-AD-PowerShell,GPMC 2. Active Directory 域服务等角色,添加成功,如图 3. Active D

Active Directory域服务

概念: 工作组:workgroup 适合网络资源少,10台左右计算机. 分散管理(对等网,每个员工维护自己的电脑,身份平等) 适合于小型网络 不便之处:为了达到互相访问的目的,可能需要在每台电脑上为其他同事建立很多用户帐号(不愿意透露管理员密码的情况下) 每台电脑自己维护管理员密码,如果忘记密码,可能由it管理员强行破解密码 每台计算机自由安装各种软件,容易引起系统崩溃 Windows域 Domain 将网络中的资源逻辑上组织到一起,将其视为一个整体.资源:计算机.用户.组.打印机.共享文件夹等

Active Directory Web 服务无法确定该计算机是否是全局编录服务器(解决办法)

我用的是windows2008R2在新建用户的时候出现一下情况: Windows 2008 的域控制器,打开 active directory 用户和计算机,就出现找不到命名信息,原因是:该服务器不可操作,如果你尝试连接到运行 windows 2000 的域控制器,请确认此dc上安装了 windows 2000 server sp3 .... dns 与这个 dc 在一台服务器上,dns 服务器能打开了,查看日志 每分钟报一次错, windows无法验证用户名的唯一性,因为在全局编录联系下发生下

Active Directory之域创建

实训要求: 1.DNS命名架构: 2.创建第一个DC+DNS; 3.域验证: 4.创建额外DC+DNS; 5.成员服务器加入.退出: 6.客户机加入.退出: 7.DC降级(成员服务器.独立服务器). Active Directory之域创建,布布扣,bubuko.com

Windows Server 笔记(六):Active Directory域服务:额外域控制器

额外域控制器: 额外域控制器是指除了第一台安装的域控制器(主域控制器)意外的所有域控制器: 那么额外域控制器有什么好处呢? 1.可以提供容错.即一台DC出问题后,另一台仍可以可以继续工作,提供服务: 2.提高用户登录效率.多台域控可以分担用户审核,加快用户登录速度: 3.备份.域控制器之间会相互复制,就等于多了一份备份: 1.首先设置好IP配置:这里首选DNS指向自己,备用DNS指向主域:将服务器加入域: 2.选择"添加角色和功能": 3.选择"下一步": 4.选择

Active Directory Recycle Bin

# Enable Active Directory Recycle Bin Enable-ADOptionalFeature  –Identity 'CN=Recycle Bin Feature,CN=Optional Features,CN=Directory  Service,CN=Windows NT,CN=Services,CN=Configuration,DC=vccware,DC=com'  –Scope ForestOrConfigurationSet –Target 'vccwa

Windows Server 2012中安装Active Directory域服务

1.登陆Windows Server 2012,打开服务器管理器,选择"添加角色和功能" 2.在"开始之前"页面,直接点击"下一步" 3.选择"基于角色或基于功能的安装",点击"下一步" 4.选择"从服务器池中选择服务器",选中当前服务器,点击"下一步" 5.在角色列表中,选择"Active Directory 域服务",点击"下一步&q