Courseiva
easyMultiple ChoiceObjective-mapped

220-1202 Practice Question: Deploy a configuration change to 50 Windows 10…

A technician needs to deploy a configuration change to 50 Windows 10 computers using a script. The script must check if a specific registry key exists before modifying it. Which scripting construct should be used?

⚠ Common exam trap

Watch out — candidates often confuse conditional logic (if-else) with error handling (try-catch), thinking that checking for existence requires exception handling, when in fact a simple conditional test is the correct and more efficient approach.

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-else statement

The script needs to conditionally execute code based on whether a registry key exists. An if-else statement is the correct construct for this because it evaluates a condition (e.g., Test-Path 'HKLM:\Software\MyKey') and executes one block if true (modify the key) and another if false (skip or create). Loops are for repetition, not conditional branching, and try-catch handles runtime errors, not existence checks.

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

    Why it's wrong here

    A for loop is a control flow statement designed for iterating a specific number of times or over a collection of items, such as elements in an array or a range of numbers. Its primary function is structured repetition of a code block. It does not inherently provide a mechanism to evaluate a condition, like the existence of a registry key, before deciding whether to perform a single, conditional configuration change; its purpose is iterative execution, not conditional pre-checks.

  • A while loop

    Why it's wrong here

    A while loop continuously executes a block of code as long as a specified condition remains true. While it does involve a condition, its primary function is repeated execution based on that condition, not a one-time conditional check followed by a single action. If the goal is to check for existence and then perform a modification once if the condition is met, a while loop would be an inefficient and inappropriate construct, potentially leading to an infinite loop if not managed carefully, or simply over-complicating a single conditional action.

  • An if-else statement

    Why this is correct

    An if-else statement is the most appropriate control structure for this scenario because it explicitly allows a script to evaluate a specific condition, such as the existence of a registry key. If the condition evaluates to true (e.g., the key exists), a defined block of code is executed. Optionally, an 'else' block can be executed if the condition is false, providing a clear path for conditional logic and ensuring the configuration change is applied only when necessary or handled differently if the key is absent.

  • A try-catch block

    Why it's wrong here

    A try-catch block is a fundamental construct for error handling and exception management within a script or program. Its purpose is to 'try' to execute a block of code that might fail, and if an error (an exception) occurs during that execution, the 'catch' block handles the error gracefully. While one could attempt to modify a non-existent key and catch the resulting error, this is an inefficient and non-idiomatic way to check for existence; it is better practice to explicitly check for existence first rather than relying on an error to determine state.

About these practice questions

Courseiva writes every 220-1202 question from scratch — 495 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.