Bird
Raised Fist0
PowerShellscripting~20 mins

Group management in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Group Management Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider the following command that lists all members of the group 'HRTeam'. What will be the output if the group has exactly two members: Alice and Bob?
PowerShell
Get-ADGroupMember -Identity HRTeam | Select-Object -ExpandProperty Name
A
Alice
Bob
B
Name
Alice
Bob
C
ObjectGUID
Name
SamAccountName
DError: The term 'Get-ADGroupMember' is not recognized
Attempts:
2 left
💡 Hint
The command lists members and selects only their names.
📝 Syntax
intermediate
2:00remaining
Which command correctly adds a user to a group?
You want to add the user 'jdoe' to the group 'FinanceTeam'. Which of the following commands will do this correctly?
AAdd-ADGroupMember FinanceTeam jdoe
BAdd-ADGroupMember -Group FinanceTeam -User jdoe
CAdd-ADGroupMember -Identity FinanceTeam -Members jdoe
DAdd-ADGroupMember -Identity jdoe -Members FinanceTeam
Attempts:
2 left
💡 Hint
Check the parameter names for the Add-ADGroupMember cmdlet.
🔧 Debug
advanced
2:00remaining
Why does this script fail to remove a user from a group?
This script is intended to remove user 'jdoe' from group 'SalesTeam', but it fails with an error. What is the cause? Remove-ADGroupMember -Identity SalesTeam -Members jdoe Error: "Cannot find an object with identity: 'jdoe'"
AThe Remove-ADGroupMember cmdlet requires the -Recursive switch.
BThe command requires the -Confirm parameter to proceed.
CThe user 'jdoe' must be specified with the full distinguished name or objectGUID.
DThe user 'jdoe' does not exist in Active Directory.
Attempts:
2 left
💡 Hint
The error says it cannot find the object 'jdoe'.
🚀 Application
advanced
2:00remaining
How to list all groups a user belongs to?
You want to find all groups that the user 'maria' is a member of. Which command will correctly list these groups?
AGet-ADUser -Identity maria -Properties MemberOf | Select-Object -ExpandProperty MemberOf
BGet-ADGroup -Filter {Members -eq 'maria'}
CGet-ADGroupMember -Identity maria
DGet-ADUser -Identity maria | Get-ADGroupMember
Attempts:
2 left
💡 Hint
User objects have a MemberOf property listing their groups.
🧠 Conceptual
expert
2:00remaining
What is the effect of the -Recursive switch in Get-ADGroupMember?
When using Get-ADGroupMember with the -Recursive switch, what is the expected behavior?
AIt lists only direct members of the group, ignoring nested groups.
BIt lists all members of the group including members of nested groups recursively.
CIt removes all members from the group recursively.
DIt adds members to the group recursively.
Attempts:
2 left
💡 Hint
Think about nested groups inside a group.

Practice

(1/5)
1. Which PowerShell cmdlet is used to create a new local group on a Windows machine?
easy
A. Add-LocalGroupMember
B. Get-LocalGroupMember
C. New-LocalGroup
D. Remove-LocalGroup

Solution

  1. Step 1: Understand the purpose of each cmdlet

    New-LocalGroup creates a new group, Add-LocalGroupMember adds users to a group, Get-LocalGroupMember lists members, Remove-LocalGroup deletes a group.
  2. Step 2: Identify the cmdlet for creating groups

    Only New-LocalGroup is used to create a new local group.
  3. Final Answer:

    New-LocalGroup -> Option C
  4. Quick Check:

    Create group cmdlet = New-LocalGroup [OK]
Hint: Remember: 'New' starts creation commands [OK]
Common Mistakes:
  • Confusing Add-LocalGroupMember as group creation
  • Using Get-LocalGroupMember to create groups
  • Trying Remove-LocalGroup to create groups
2. Which of the following is the correct syntax to add a user named 'Alice' to a local group called 'Developers'?
easy
A. Add-LocalGroupMember -Group 'Developers' -Member 'Alice'
B. Add-LocalGroupMember -Member 'Developers' -Group 'Alice'
C. New-LocalGroup -Group 'Developers' -Member 'Alice'
D. Get-LocalGroupMember -Group 'Developers' -Member 'Alice'

Solution

  1. Step 1: Identify the cmdlet to add members

    Add-LocalGroupMember is used to add users to groups.
  2. Step 2: Check parameter order and names

    The correct syntax uses -Group for the group name and -Member for the user name.
  3. Final Answer:

    Add-LocalGroupMember -Group 'Developers' -Member 'Alice' -> Option A
  4. Quick Check:

    Add user syntax = Add-LocalGroupMember -Group -Member [OK]
Hint: Group comes before Member in Add-LocalGroupMember [OK]
Common Mistakes:
  • Swapping -Group and -Member parameters
  • Using New-LocalGroup to add members
  • Using Get-LocalGroupMember to add members
3. What will be the output of this PowerShell command if the 'TestGroup' has members 'Bob' and 'Carol'?
Get-LocalGroupMember -Group 'TestGroup' | Select-Object -ExpandProperty Name
medium
A. Bob Carol
B. Name Bob Carol
C. TestGroup
D. Error: Group not found

Solution

  1. Step 1: Understand Get-LocalGroupMember output

    This cmdlet lists members of the specified group with properties like Name.
  2. Step 2: Effect of Select-Object -ExpandProperty Name

    This extracts only the Name property values, outputting member names as plain strings.
  3. Final Answer:

    Bob Carol -> Option A
  4. Quick Check:

    Extracted names list = Bob and Carol [OK]
Hint: Select -ExpandProperty outputs only the property values [OK]
Common Mistakes:
  • Expecting property headers in output
  • Confusing group name with member names
  • Assuming error if group exists
4. You run this command but get an error: Add-LocalGroupMember -Group 'Admins' -Member 'John'. What is the most likely cause?
medium
A. The syntax is incorrect
B. The 'Admins' group does not exist
C. The 'John' user is already a member
D. You are not running PowerShell as administrator

Solution

  1. Step 1: Check permissions needed for group changes

    Modifying local groups requires administrator privileges in PowerShell.
  2. Step 2: Analyze error cause

    If the group exists and syntax is correct, lack of admin rights causes permission errors.
  3. Final Answer:

    You are not running PowerShell as administrator -> Option D
  4. Quick Check:

    Admin rights needed for group changes [OK]
Hint: Always run PowerShell as admin for group management [OK]
Common Mistakes:
  • Assuming syntax error without checking permissions
  • Ignoring admin rights requirement
  • Thinking user membership causes error
5. You want to create a new local group named 'ProjectTeam' and add multiple users: 'Alice', 'Bob', and 'Carol'. Which script correctly does this in PowerShell?
hard
A. Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Alice'; Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Bob'; Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Carol'
B. New-LocalGroup -Name 'ProjectTeam'; Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Alice','Bob','Carol'
C. New-LocalGroup -Name 'ProjectTeam' -Member 'Alice','Bob','Carol'
D. New-LocalGroup -Group 'ProjectTeam'; Add-LocalGroupMember -Member 'Alice','Bob','Carol'

Solution

  1. Step 1: Create the group first

    Use New-LocalGroup with -Name to create 'ProjectTeam'.
  2. Step 2: Add multiple members in one command

    Add-LocalGroupMember accepts multiple members as a comma-separated list.
  3. Step 3: Verify syntax correctness

    New-LocalGroup -Name 'ProjectTeam'; Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Alice','Bob','Carol' correctly creates the group then adds all members in one command.
  4. Final Answer:

    New-LocalGroup -Name 'ProjectTeam'; Add-LocalGroupMember -Group 'ProjectTeam' -Member 'Alice','Bob','Carol' -> Option B
  5. Quick Check:

    Create group then add members list [OK]
Hint: Create group first, then add all members together [OK]
Common Mistakes:
  • Trying to add members during group creation
  • Using wrong parameter names
  • Adding members before group exists