Aug 21 2019 03:50 AM
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?
Aug 21 2019 08:54 AM
SolutionThat'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
Aug 22 2019 03:29 AM
Big thanks @Vasil Michev !
Now I have learnt once more something new :D
Aug 21 2019 08:54 AM
SolutionThat'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