How to pull report of computers from Active Directory with the container they are in

Hisham Rafi 21 Reputation points
2022-06-30T16:04:55.087+00:00

I have a list of 50+ computers that i need to send to an excel sheet or any document but it needs to list containers for each of the PC's. Is there a way to do that?

Windows for business Windows Server User experience PowerShell
Microsoft Security Intune Configuration Manager Other
{count} votes

1 answer

Sort by: Most helpful
  1. Newbie Jones 1,386 Reputation points
    2022-07-01T10:19:07.893+00:00

    DistinguishedName is a default attribute for Get-ADComputer.

    If you just want the container OU, you can split the distinguished name via the following method.

    (Get-ADComputer computername).distinguishedName.split(',',2)[1]  
    

    This splits the distinguisedName into two parts separated by a comma, and then returns the second element in that array.
    The information before the first comma is generally the canonical name. (CN=).

    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.