PowerShell Genie
Practice Sort Azure VMs by name

Sort Azure VMs by name

Exercise 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Return all VMs in alphabetical order with their power states.

An example to inspect

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

Get-AzVM -Status | Sort-Object Name | Select-Object Name, PowerState

The task

The monthly inventory report lists every VM alphabetically, with its current state beside the name.

Target

Return all VMs in alphabetical order with their power states.

What the result tells you

Sort-Object Name orders the inventory; keeping PowerState in the selection shows which entries need attention.

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 keep PowerState in the selection?

Choose an answer, then check your reasoning.

Worked solution

Worked solution

Reveal one approach
1PS> Get-AzVM -Status | Sort-Object Name | Select-Object Name, PowerState

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 Azure VMs by name

Return all VMs in alphabetical order with their power states.