SOLVED

How to sort when using custom tables

Bronze Contributor

Hi

I have a registry hives where I have same information on all of them. I would like to read the values from all of those hives, and then sort output based on the values.

 

Here I have simple example of the similar CMDLet:

Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services -Depth 0 | format-table @{Label="Services"; Expression={(Get-ItemProperty -Path $_.PSPath).DisplayName}}, @{Label="Start"; Expression={(Get-ItemProperty -Path $_.PSPath).Start}}

Above basically read the services and print out the displayname and start type. But I realised that sort-object is not working, neither convertto-csv. Any ideas if this is even doable?

2 Replies
best response confirmed by Petri X (Bronze Contributor)
Solution

That's because you are using Format-Table. Use a simple Select instead.

 

Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services -Depth 0 | Select @{Label="Services"; Expression={(Get-ItemProperty -Path $_.PSPath).DisplayName}}, @{Label="Start"; Expression={(Get-ItemProperty -Path $_.PSPath).Start}} | sort Start -Descending

Big thanks @Vasil Michev  !

Now I have learnt once more something new :D

1 best response

Accepted Solutions
best response confirmed by Petri X (Bronze Contributor)
Solution

That's because you are using Format-Table. Use a simple Select instead.

 

Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services -Depth 0 | Select @{Label="Services"; Expression={(Get-ItemProperty -Path $_.PSPath).DisplayName}}, @{Label="Start"; Expression={(Get-ItemProperty -Path $_.PSPath).Start}} | sort Start -Descending

View solution in original post