How to get a list of OU paths from Active Directory RRS feed

  • Question

  • Hi,

    I could use some help with ideas for writing a script that will give me a list of all Active Directory paths that end in 'OU=Computers'. Here is an example:

    OU=Computers,OU=Aberdeen,OU=PNW,DC=usa,DC=com (returning distinguished name is preferred)

    This will end up with a fairly long list in our environment after the script inspects all available OUs that end with Computers. I'm not looking for a complete solution but some coaching would be greatly appreciated!

    Thank you!


    Wednesday, December 26, 2018 7:33 PM


All replies

  •  Get-AdObject -filter 'Name -eq "Computers" -and objectClass -eq "OrganizationalUnit"'


    Wednesday, December 26, 2018 7:40 PM
  • I should also note that the leftmost part of a DN is the "Name" or "CN" of the object.  If you are sure you only want organizationalUnits then use the normal command.

    Get-AdOrganizationalUnit -Filter 'Name -eq "Computers"'

    Both versions will not return the built-in "Computers" container.  An OU is a special version of a container.  To get all containers named "Computers" then do the following.

    Get-AdObject -filter 'Name -eq "Computers"'


    • Edited by jrv Wednesday, December 26, 2018 7:49 PM
    Wednesday, December 26, 2018 7:49 PM
  • I definitely only need the paths ending in OU=Computers. I don't need a list of devices contained in the OU in this case. I will be using the output to update the XML used by the UDI Wizard in SCCM.

    We have so many OUs ending with 'Computers' that it could definitely result in errors if doing this manually. I want to be sure I don't miss any of these OUs in my XML file and this seems like a good approach.

    Wednesday, December 26, 2018 7:55 PM