0
0
PowerShellscripting~30 mins

Organizational unit operations in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Organizational Unit Operations with PowerShell
📖 Scenario: You work in an IT department managing Active Directory. You need to automate tasks related to Organizational Units (OUs) to keep the directory organized.
🎯 Goal: Build a PowerShell script that creates a list of OUs, sets a filter for OUs starting with a specific prefix, retrieves those OUs, and then displays their names.
📋 What You'll Learn
Create a list of Organizational Units (OUs) with exact names
Add a filter variable to select OUs starting with a specific prefix
Use a loop to filter OUs based on the prefix
Print the filtered OU names
💡 Why This Matters
🌍 Real World
Automating management of Active Directory Organizational Units saves time and reduces errors in IT environments.
💼 Career
PowerShell scripting for Active Directory is a key skill for system administrators and IT support professionals.
Progress0 / 4 steps
1
Create the list of Organizational Units
Create a variable called OUs and assign it an array with these exact strings: 'HR', 'Finance', 'IT', 'IT-Support', 'Marketing'.
PowerShell
Need a hint?

Use @( ... ) to create an array in PowerShell.

2
Add a filter prefix variable
Create a variable called prefix and set it to the string 'IT'.
PowerShell
Need a hint?

Assign the string 'IT' to the variable prefix.

3
Filter OUs starting with the prefix
Create a variable called filteredOUs and assign it the result of filtering $OUs to include only those that start with the value in $prefix. Use a foreach loop with variables ou and an if statement checking $ou.StartsWith($prefix).
PowerShell
Need a hint?

Use foreach to check each OU and add matching ones to filteredOUs.

4
Display the filtered Organizational Units
Use Write-Output to print the contents of the variable filteredOUs.
PowerShell
Need a hint?

Use Write-Output $filteredOUs to show the filtered list.