Explain the command and each part : Get-Service * | Select-Object Status, DisplayName | Where-Object { $_.Status -eq “Running” -and $_.DisplayName -like “Windows*“ } | Sort-Object DisplayName -Descending | Format-Table -AutoSize

This command lists running Windows services whose display name starts with “Windows”, sorts them by display name in descending order, and displays the result in a neat table.

Corrected version:

Get-Service * |
Select-Object Status, DisplayName |
Where-Object { $_.Status -eq "Running" -and $_.DisplayName -like "Windows*" } |
Sort-Object DisplayName -Descending |
Format-Table -AutoSize

Step-by-step explanation

1. Get-Service *

Get-Service *

Gets all Windows services on the computer.

The * wildcard means:

all services

So this returns services such as:

Windows Update
Windows Audio
Print Spooler
BITS

2. Pipeline |

|

The pipeline sends the output of one command to the next command.

Here, service objects are passed from:

Get-Service

to:

Select-Object

3. Select-Object Status, DisplayName

Select-Object Status, DisplayName

Keeps only two properties:

PropertyMeaning
StatusWhether the service is Running, Stopped, etc.
DisplayNameThe friendly service name shown to users

Example output at this stage:

Status   DisplayName
------   -----------
Running  Windows Audio
Stopped  Windows Search
Running  Windows Update

4. Where-Object { ... }

Where-Object { $_.Status -eq "Running" -and $_.DisplayName -like "Windows*" }

This filters the services.

Only services that meet both conditions are kept.


5. $_

$_

Means:

the current object in the pipeline

In this command, each $_ represents one service object.


6. $_.Status -eq "Running"

$_.Status -eq "Running"

Checks whether the service status is exactly:

Running

-eq means:

equals

7. -and

-and

Means both conditions must be true.

So the service must be:

Running

and its display name must start with:

Windows

8. $_.DisplayName -like "Windows*"

$_.DisplayName -like "Windows*"

Checks whether the service display name starts with Windows.

-like is used for wildcard pattern matching.

The * means:

anything after Windows

Examples that match:

Windows Audio
Windows Update
Windows Event Log
Windows Search

Examples that do not match:

Print Spooler
Background Intelligent Transfer Service

9. Sort-Object DisplayName -Descending

Sort-Object DisplayName -Descending

Sorts the remaining services by DisplayName.

-Descending means:

Z to A

Without -Descending, it would sort:

A to Z

10. Format-Table -AutoSize

Format-Table -AutoSize

Displays the final output as a table.

-AutoSize adjusts column widths so the output is easier to read.


Full meaning in one sentence

Get-Service * |
Select-Object Status, DisplayName |
Where-Object { $_.Status -eq "Running" -and $_.DisplayName -like "Windows*" } |
Sort-Object DisplayName -Descending |
Format-Table -AutoSize

means:

Get all services, keep only Status and DisplayName, filter only running services whose display name starts with “Windows”, sort them by DisplayName from Z to A, and display the result in a neat table.

Important note

Your original command has a curly closing quote here:

"Windows*“

Use a normal straight quote instead:

"Windows*"

REF: AI Tools/ChatGPT

Leave a Reply