PowerTip: Querying Active Directory via PowerShell

Summary: Learn how to query Active Directory via Windows PowerShell.

Hey, Scripting Guy! Question Can you name five ways to query Active Directory from within Windows PowerShell?

Hey, Scripting Guy! Answer

  1. Use ADO and perform an LDAP dialect query.
  2. Use ADO and perform an SQL dialect query.
  3. Use the Get-ADObject cmdlet from the Active Directory module.
  4. Use DSQuery.
  5. Use the [ADSISearcher] type accelerator.

Comments (7)

  1. jrv says:

    The ADO bits are excellent.  We don't ever seem to use them.  They can actually create a recordset that can be sorted and bulfk loaded into a database,

    This was a good PowerTip.

  2. mredwilson says:

    @Yanan Wang you are right. I fat fingered it (Word does not have tab expansion unfortunately). I have updated the article. Thanks for catching this.

  3. Brian Finn says:

    I like to use Quest's Active Directory commandlets.

  4. Ed Wilson says:

    @Brian Finn lots of people use the Quest AD cmdlets. They were the first ones out there with cmdlets and filled a real need.

    @JRV yes, I still use ADO from time to time. Especially on systems where they have a strong VBScript background, and no .NET experience.

  5. Yanan Wang says:

    There is no Get-ADOObject cmdlet from ActiveDirectory Module. The name of the cmdlet should be:


  6. dheeraj says:

    Can you give a few examples for making ADODB objects in Powershell to connect to AD?

Skip to main content