0
0
PowerShellscripting~30 mins

Group management in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Group management
📖 Scenario: You are managing user groups on a system. You want to organize users into groups and then list the members of groups that have more than a certain number of users.
🎯 Goal: Create a PowerShell script that defines groups with users, sets a minimum member count, filters groups by that count, and displays the filtered groups.
📋 What You'll Learn
Create a hashtable called groups with exact group names and user lists
Create a variable called minCount with the value 3
Use a foreach loop with variables groupName and userList to iterate over groups.GetEnumerator()
Inside the loop, use an if statement to check if userList.Count is greater than or equal to minCount
Create a new hashtable called filteredGroups to store groups meeting the condition
Print the filteredGroups hashtable at the end
💡 Why This Matters
🌍 Real World
System administrators often manage user groups to control access and permissions. Filtering groups by size helps in auditing and reporting.
💼 Career
Knowing how to script group management tasks in PowerShell is valuable for IT support, system administration, and automation roles.
Progress0 / 4 steps
1
Create the groups hashtable
Create a hashtable called groups with these exact entries: 'Admins' with users 'Alice', 'Bob', 'Charlie'; 'Editors' with users 'Dave', 'Eve'; and 'Viewers' with users 'Frank', 'Grace', 'Heidi', 'Ivan'.
PowerShell
Need a hint?
Use @{} to create a hashtable and @() to create arrays of users.
2
Set the minimum member count
Create a variable called minCount and set it to 3.
PowerShell
Need a hint?
Just assign the number 3 to the variable minCount.
3
Filter groups by minimum member count
Create an empty hashtable called filteredGroups. Use a foreach loop with variables groupName and userList to iterate over $groups.GetEnumerator(). Inside the loop, use an if statement to check if userList.Count is greater than or equal to minCount. If yes, add the group to filteredGroups with groupName as key and userList as value.
PowerShell
Need a hint?
Use GetEnumerator() to loop through hashtable keys and values, then check count and add to filteredGroups.
4
Display the filtered groups
Print the filteredGroups hashtable using Write-Output.
PowerShell
Need a hint?
Use Write-Output to display the hashtable. Only groups with 3 or more users appear.