mediumMultiple ChoiceObjective-mapped
220-1102 Practice Question: A technician is writing a PowerShell script to…
A technician is writing a PowerShell script to check the status of a Windows service on multiple remote computers. The script must output the service name and status for each computer where the service is running. Which cmdlet combination should the technician use to achieve this?
⚠ Common exam trap
CompTIA often tests the distinction between Get-Service and Get-WmiObject Win32_Service, where candidates confuse the property names 'Status' vs 'State' and the correct filtering syntax, leading them to choose option C despite its deprecated status and incorrect property reference.
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
✓
Get-Service -ComputerName $computers | Where-Object {$_.Status -eq 'Running'}
Get-Service with the -ComputerName parameter can query multiple remote computers directly, and piping its output to Where-Object with the condition {$_.Status -eq 'Running'} filters only services whose Status property equals 'Running'. This meets the requirement to output the service name and status for each computer where the service is running, as Get-Service returns objects containing both Name and Status properties by default.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Get-Service -ComputerName $computers | Where-Object {$_.Status -eq 'Running'}
Why this is correct
This command leverages the Get-Service cmdlet, which is the standard PowerShell method for interacting with Windows services. The -ComputerName parameter allows specifying one or more remote machines, making it suitable for checking multiple computers. Piped to Where-Object, it filters the results based on the Status property, specifically selecting only those services whose status is 'Running', directly fulfilling the requirement to identify running services.
- ✗
Invoke-Command -ComputerName $computers -ScriptBlock {Get-Service} | Select-Object Status
Why it's wrong here
While Invoke-Command is effective for executing scripts on remote computers and Get-Service correctly retrieves service information, piping its output to Select-Object Status would only display the numerical or string representation of the service's operational state. This approach fails to include crucial identifying information such as the service Name or DisplayName, which are essential for a technician to understand which services are running. Therefore, it does not provide a complete and useful list of running services.
- ✗
Get-WmiObject Win32_Service -ComputerName $computers | Where-Object {$_.State -eq 'Running'}
Why it's wrong here
This command utilizes Get-WmiObject to query the Win32_Service WMI class, which is a legacy method for service management in PowerShell. Although it can retrieve service information, modern PowerShell best practices favor native cmdlets like Get-Service for better performance and integration. Furthermore, the Win32_Service class uses the property State (e.g., 'Running', 'Stopped') to describe a service's condition, whereas Get-Service uses Status, making the property name incorrect for a native cmdlet approach.
- ✗
Get-Service -Name * -ComputerName $computers | Format-Table -AutoSize
Why it's wrong here
This command successfully retrieves all services from the specified remote computers using Get-Service -Name * and then formats the output into a readable table using Format-Table -AutoSize. However, the core requirement is to identify only the services that are currently running. This command lacks any filtering mechanism, such as Where-Object, to narrow down the results to just running services, thus presenting an overwhelming amount of irrelevant data to the technician.
Go deeper
Related to this question
Learn chapter
Windows Editions and Features
Key term
Object
In IT and cloud computing, an object is a discrete unit of data stored in a structure that pairs the data with its metadata and a unique identifier, enabling scalable access without a traditional folder hierarchy.
Key term
PowerShell
PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and a scripting language built on the .NET framework.
About these practice questions
This 220-1202 question is part of Courseiva's 495-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.