hardMultiple ChoiceObjective-mapped
220-1102 Practice Question: A technician is tasked with creating a PowerShell…
A technician is tasked with creating a PowerShell script that will parse a CSV file containing user information and create local user accounts on a Windows 10 machine. The CSV has columns: 'Username', 'FullName', 'Password'. The script must skip any row where the 'Username' is empty. Which control structure should the technician use to handle this requirement?
⚠ Common exam trap
CompTIA often tests the distinction between control structures used for conditional logic versus iteration or error handling, and the trap here is that candidates may overcomplicate the solution by choosing a loop or switch when a simple conditional check is the most appropriate and efficient choice.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
An 'if' statement to test whether the Username property is not empty
The requirement is to conditionally skip rows based on a property value. An 'if' statement in PowerShell allows you to test whether the 'Username' property is empty or null using a condition like `if ($_.Username -ne '')` and then skip the row with `continue` or simply not process it. This is the most direct and efficient control structure for a simple boolean check on each row.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
A 'for' loop with a counter to skip empty rows
Why it's wrong here
A 'for' loop is primarily used for iterating a specific number of times or over a collection of items. While it provides the structure for processing each row, it does not inherently contain the logic to *detect* or *skip* an empty row or property. An additional conditional statement, such as an 'if' statement, would be required *inside* the loop to perform the actual check for an empty username and then conditionally bypass processing.
- ✗
A 'switch' statement to match usernames
Why it's wrong here
A 'switch' statement is designed to evaluate a single expression against multiple potential values or patterns, executing different code blocks based on which case matches. While useful for branching logic based on specific username values (e.g., 'admin', 'guest'), it is not intended for, nor does it provide, a mechanism to simply *skip* processing if a property like 'Username' is found to be empty. Its purpose is conditional execution, not data validation for emptiness.
- ✓
An 'if' statement to test whether the Username property is not empty
Why this is correct
An 'if' statement is the most direct and appropriate control flow construct for evaluating a specific condition and executing code only if that condition is true. By testing whether the 'Username' property is not null or empty, the script can precisely determine if valid data exists. This allows the script to prevent account creation attempts for incomplete entries, ensuring data integrity and preventing unnecessary errors.
- ✗
A 'try/catch' block to handle errors when creating the account
Why it's wrong here
A 'try/catch' block is a robust error handling mechanism used to gracefully manage unexpected runtime exceptions that may occur during script execution, such as network issues or database errors during account creation. While essential for making scripts resilient, it does not *prevent* an empty username from being passed to the account creation command. An empty username would likely cause a validation error *during* the command execution, which 'try/catch' could then *handle*, but it wouldn't *pre-emptively skip* the attempt itself.
Go deeper
Related to this question
Learn chapter
Windows Editions and Features
Key term
Windows 10
Windows 10 is a personal computer operating system developed by Microsoft that combines the familiarity of Windows 7 with the modern features of Windows 8, designed to run on a wide range of devices from desktops to tablets.
Key term
Windows
Windows is a family of operating systems developed by Microsoft that manages computer hardware and software, providing a graphical user interface for users to interact with their devices.
About these practice questions
One of 495 original 220-1202 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 220-1202 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 220-1202 exam.