question

LukasPiech-7028 avatar image
0 Votes"
LukasPiech-7028 asked LukasPiech-7028 answered

Sort-Object 'Top' parameter in powershell version 5

Dear All,
I am having a problem with following command when working with powershell in version 5:

 $Folder = "C:\Temp"
 Get-ChildItem $folder | Sort-Object -Descending -Property LastWriteTime -Top 1 

Below error message that i am receiving:

A parameter cannot be found that matches parameter name 'Top'

Any hints how to overcome this issue?
Regards,
Lukas

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

Use Select-Object on the result of the Sort-Object.

 $Folder = "C:\Temp"
 Get-ChildItem $folder | 
     Sort-Object -Descending -Property LastWriteTime |
         Select-Object -First 1 
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered RichMatheisen-8856 commented

Hello @LukasPiech-7028

Never used -Top parameter before. I always use "-First" to show the top results. Have you tried:

  $Folder = "C:\Temp"
  Get-ChildItem $folder | Sort-Object -Descending -Property LastWriteTime -First 1 

Hope this helps,
Regards,



--If the the reply is helpful, please Upvote and Accept as answer--

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There is no -First parameter for the Sort-Object cmdlet!

sort-object


0 Votes 0 ·
LukasPiech-7028 avatar image
0 Votes"
LukasPiech-7028 answered

Thank you Both for replying!

I've used RichMatheisen-8856 solution, it works just as i wanted!

Regards,
Lukas

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.