PowerShell Genie
Practice Sort AD accounts by name

Sort AD accounts by name

Exercise 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Return all accounts in alphabetical order, showing whether each is enabled.

An example to inspect

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

Get-ADUser -Filter * | Sort-Object Name | Select-Object Name, Enabled

The task

The quarterly access review needs one row per account in alphabetical order, with the account state visible next to each name.

Target

Return all accounts in alphabetical order, showing whether each is enabled.

What the result tells you

Sort-Object orders the objects first, while every property is still available; Select-Object then trims the report to the columns you need.

Verify the result

Run the source by itself and inspect the sample objects. Add each filter separately, then check the final properties and order.

The browser uses a small fictional dataset. Real results depend on the host, module, account and target environment.

Why sort before selecting properties?

Choose an answer, then check your reasoning.

Worked solution

Worked solution

Reveal one approach
1PS> Get-ADUser -Filter * | Sort-Object Name | Select-Object Name, Enabled

Related reference

Read the command and platform requirements
Next exercise

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
Genie guideSort AD accounts by name

Return all accounts in alphabetical order, showing whether each is enabled.