Get all active directory computers from all domains

Rob M 61 Reputation points
2022-03-28T22:01:00+00:00

Hi,

I need to get all Active Directory computers from five different domains. The script below has executed without errors except for one domain. This is the code I am using:

Get-ADComputer -Filter * -Properties * -Server "server.domain.com"  | Select-Object Name

This is the error I am seeing:

Get-ADComputer : Directory object not found
At line:1 char:1
+ Get-ADComputer -Filter * -Properties * -Server "server.domain.com"   ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-ADComputer], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Comm 
   ands.GetADComputer

I get that the error message says the Directory object is not found but without changing anything but the server name, the script is working fine in the other domains.

Thank you!
Rob

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-03-28T22:47:12.823+00:00

    Is server.domain.com a Global Catalog Server? If it is, use "server.domain.com:3268" instead of just the server name. You'll probably have to add a -SearchBase to the cmdlet, too. The value of that should be the root domain of the AD forest. That should search ALL domains in the AD forest.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rob M 61 Reputation points
    2022-03-28T22:09:30.807+00:00

    I made one change and it seems to be working now:

    Get-ADComputer -Filter * -Properties Name -Server "server.domain.com"  | Select-Object Name
    

    I added in the name of a property before the pipe, Name.

    The other domains didn't need anything other than -Properties *. Why is this domain different?

    -Rob

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.