none
Get all computer names in Active Directory Computers OU RRS feed

  • Question

  • I am using the following script to export a txt file of computer object names from various OU's but I am unable to run it against the Computers OU.

    Get-ADComputer-SearchBase"OU=Computers,dc=corp,Dc=MyDomainName,dc=com"|Select-Object-ExpandPropertyName|Out-FileC:\Temp\Computer.txt

    Error:

    Get-ADComputer : Directory object not found

    At C:\Users\sdr-XXX\Desktop\GetOUMemberList.ps1:1 char:1

    + Get-ADComputer -SearchBase "OU=Computers,dc=corp,Dc=MyDomainName,dc=co ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : ObjectNotFound: (:) [Get-ADComputer], ADIdentityNotFoundException

        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADComputer


    DHeinz

    Wednesday, January 4, 2017 5:29 PM

Answers

  • Read the error message first: "Directory object not found". This is literally correct.

    The default Computers container in AD is not an OU. It has a distinguishedName that starts with CN instead of OU.

    With this knowledge: What should you change in your Get-ADComputer command to make this work correctly?


    -- Bill Stewart [Bill_Stewart]


    Wednesday, January 4, 2017 5:52 PM
    Moderator

All replies

  • Hi,

    Hope you have import the Activedirectory module first.

    Did you use the elevated PowerShell and try the script.

    And found this article, maybe it will help

    https://blogs.technet.microsoft.com/askds/2010/02/04/inventorying-computers-with-ad-powershell


    Hemal

    Wednesday, January 4, 2017 5:43 PM
  • Thanks for your reply, as I stated, the Powershell scripts works when I point to other OU's just not the Computers OU.

    DHeinz

    Wednesday, January 4, 2017 5:50 PM
  • Read the error message first: "Directory object not found". This is literally correct.

    The default Computers container in AD is not an OU. It has a distinguishedName that starts with CN instead of OU.

    With this knowledge: What should you change in your Get-ADComputer command to make this work correctly?


    -- Bill Stewart [Bill_Stewart]


    Wednesday, January 4, 2017 5:52 PM
    Moderator
  • Thanks Bill it worked perfectly.

    DHeinz

    Wednesday, January 4, 2017 5:54 PM