From the course: Complete Guide to PowerShell 7

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Sorting objects

Sorting objects

- [Instructor] Now another useful command is the sort-object, which allows us to sort things by specific properties. So if I get my list of processes, and of course when we render that, it comes back with this full list of properties that are available, and you can see one of those is CPU. So let's say I wanted to sort that by descending order. I can run that selection again. And sure enough, you'll see this number's the biggest. And then if we scroll all the way back up here, let me find that top of the list, this one, it'll then say my CPU is up here. So here's my most used. Now, we can also combine this with our select statements that we already had. So we can then say get process, pipe it to the sort object to put it in the right order, and then select the fields that we wish to show. So if we select that, you'll see, then it creates a different one. It comes back and says, okay, I've got the property of the CPU, I've got the name 'cause that's what we selected. I've put it in…

Contents