PowerShell Genie

Find the DNS service by name in PowerShell

Exercise 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Write a pipeline, run it against the sample data, and check your result.

An example to inspect

Preview the example. Sign in for the full lesson and activities.

Get-Service -Name 'Dns*'

Target

Return the service whose Name matches Dns*.

Expected result

Dnscache

Try the task

Show a worked solution
Reveal one approach
1PS> Get-Service -Name 'Dns*'

Try it in the lab

Write your pipeline below and run it against the fictional sample data, then check your result against the expected answer.

Interactive simulation · fictional data

PowerShell skills

Service objects · Wildcard matching

Build the answer in three decisions

Read the pipeline from left to right. Each stage receives objects from the stage before it.

Collect

Get-Service -Name 'Dns*'

Start with 7 fictional service objects. Keep them as objects so later stages can inspect their properties.

Shape

Inspect the source properties

Apply the condition or ordering required by the task. Get-Service accepts a wildcard Name.

Verify

Check the returned names

The fixture should return Dnscache. For this exercise, equivalent matching names can pass even when their order is different.

Reason through the pipeline

The source stage returns 7 service objects. Then the pipeline applies the task condition without converting the objects to display text. That keeps the Name property available for the checker and for any later pipeline stage.

Why common attempts fail

Keep the answer as a pipeline over the fixture instead of typing the expected result directly.

What the checker accepts

The evaluator runs the supported subset against the same fictional fixture. It expects Dnscache. The checker compares the matching names without requiring a specific order. Equivalent supported syntax is accepted.

Verify another attempt

First run Get-Service -Name 'Dns*' by itself and inspect the fixture. Then add one stage at a time and compare how many objects remain. This isolates the stage that changes the result and makes the final pipeline easier to explain and debug.

Primary documentation

PowerShell pipeline behavior

Next exercise
Genie guideFind the DNS service by name in PowerShell

Write a pipeline, run it against the sample data, and check your result.