Powershell Tutorial – Get a list of all users from an OU

0Shares
Reading Time: 2 minutes

Powershell Tutorial | How to grab all users in a specific Organizational Unit

Heres a simple powershell tutorial to help you through your systems administration journey. If you ever need to find user information within a specific OU, feel free to use this script below.



The Code

Download this powershell script on github

 

Breaking it down

This one is pretty simple. First I specified with OU I wanted to run my search in and stored it in the $OU variable.

Then we ran Get-ADUser, set the filter to * to grab all the users in the OU, set the search base to our $OU and then selected the name and username.

If we wanted to, we could’ve stored the results in a csv or text file. Feel free to modify or change this script as you see fit. These were our results below from our test environment.

powershell script

 

Interested In learning Powershell?

Check out “Mastering Windows PowerShell Scripting – Second Edition: One-stop guide to automating administrative tasks“. This comprehensive guide starts from scratch and covers advanced-level topics to make you a PowerShell expert. The first module, PowerShell Fundamentals, begins with new features, installing PowerShell on Linux, working with parameters and objects, and also how you can work with .NET classes from within PowerShell. Click the image below to purchase.

 

This post is located under the Programming Category

Learn how to create a Russian Roulette game written in Powershell!

0Shares

admin

Leave a Reply

Your email address will not be published.