Forum Discussion

tylerjohnson0526's avatar
tylerjohnson0526
Copper Contributor
Nov 08, 2021

Using Get-ADComputer Syntax

Hello all,

 

I am attempting to gain inventory on newly installed SSD drives in workstations. When I use "get-adcomputer" and use "-filter *" does this grab computers listed in all domain controllers or just one particular DC?

 

Thanks.

2 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    tylerjohnson0526 

     

    Active Directory is a multi-master directory service. This means that all domain controllers hold exactly the same information (allowing for minor variations where inter-site replication takes place).

     

    It does not matter which domain controller you run your query against, they will return the same result set.

     

    If you're in a forest with more than one domain, the domain queried will be governed by the defaultNamingContext associated with your computer's account. You can verify this value with the following PowerShell command:

     

     

    ([adsi]"LDAP://RootDSE").defaultNamingContext

     

     

    As per AndySvints' comment, you can override this default search location using a combination of -SearchBase, -SearchScope and -Server.

     

    Note: If you are in a multi-domain forest, searching the forest root will not allow you to discover computers in the child domains (by default). You can get around this by specifying that you wish to run your search against a global catalog server (GC) but this comes with the trade off that not all the class' attributes are available in such a search.

  • AndySvints's avatar
    AndySvints
    Iron Contributor

    Hello tylerjohnson0526,

    AFAIK it grabs the list of computers in Active Directory Forest (All DCs).

    In your command you are not specifying SearchBase and Server parameters.

    From the help & documentation of -SearchBase:

    "the default value of this parameter is the default naming context of the target domain."

    Help & documentation of -Server:

    "The default value for this parameter is determined by one of the following methods in the order that they are listed:

    • By using the Server value from objects passed through the pipeline
    • By using the server information associated with the Active Directory Domain Services Windows PowerShell provider drive, when the cmdlet runs in that drive
    • By using the domain of the computer running Windows PowerShell"

    Reference: https://docs.microsoft.com/en-us/powershell/module/activedirectory/get-adcomputer?view=windowsserver2019-ps

     

    Hope that helps.

Resources