Bird
0
0

You need to create multiple OUs named 'Dept1', 'Dept2', and 'Dept3' under 'OU=Company,DC=example,DC=com'. Which script snippet correctly automates this?

hard📝 Application Q8 of 15
PowerShell - Active Directory
You need to create multiple OUs named 'Dept1', 'Dept2', and 'Dept3' under 'OU=Company,DC=example,DC=com'. Which script snippet correctly automates this?
ARemove-ADOrganizationalUnit -Name 'Dept1','Dept2','Dept3' -Path 'OU=Company,DC=example,DC=com'
BNew-ADOrganizationalUnit -Name 'Dept1','Dept2','Dept3' -Path 'OU=Company,DC=example,DC=com'
CGet-ADOrganizationalUnit -Filter 'Name -in "Dept1","Dept2","Dept3"' | New-ADOrganizationalUnit
Dforeach ($name in 'Dept1','Dept2','Dept3') { New-ADOrganizationalUnit -Name $name -Path 'OU=Company,DC=example,DC=com' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to create multiple OUs

    Using a foreach loop to iterate over names and create each OU is correct.
  2. Step 2: Evaluate other options

    New-ADOrganizationalUnit -Name 'Dept1','Dept2','Dept3' -Path 'OU=Company,DC=example,DC=com' tries to create multiple OUs in one command which is invalid. Get-ADOrganizationalUnit -Filter 'Name -in "Dept1","Dept2","Dept3"' | New-ADOrganizationalUnit misuses Get-ADOrganizationalUnit and piping. Remove-ADOrganizationalUnit -Name 'Dept1','Dept2','Dept3' -Path 'OU=Company,DC=example,DC=com' deletes OUs instead of creating.
  3. Final Answer:

    foreach ($name in 'Dept1','Dept2','Dept3') { New-ADOrganizationalUnit -Name $name -Path 'OU=Company,DC=example,DC=com' } -> Option D
  4. Quick Check:

    Use foreach loop to create multiple OUs [OK]
Quick Trick: Use foreach loop to create multiple OUs one by one [OK]
Common Mistakes:
  • Trying to create multiple OUs in one command
  • Confusing Get- and New- cmdlets
  • Using Remove- instead of New-

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes