Greetings!
I’ve recently decided to make a concerted effort to expand my skill set in Powershell. To that end, I’ve been searching on the Internet for some challenges to do in my free time. The current one I’m working on is as follows:
Create a script that searches for user accounts in each OU in the domain. For each OU that contains user accounts, display the OU name heading followed by a list of user accounts.
Your output should look similar to the following:
Customer Support Users
John Doe XVI
Finance Users
Jane Doe
Where I’m At Right Now:
>> I’m able to get a list of users using either Get-ADUser or Get-ADObject and I can kinda get the OU by selecting CanonicalName or DistinguishedName, though it’s obviously buried.
>> I’m able to get a list of OU’s with Get-ADOrganizationalUnit.
The issue I’m having is that I can’t quite figure out how to format the list in the way its being presented in the challenge.
Judging from the research I’ve done online thus far, I have this icky feeling that I may need to use RegEx to extract JUST the name of the OU from the user’s CN or DN string.
I would appreciate any help that anyone is willing to provide. Thanks in advance for your assistance and valuable time!
Regards,
~Will~