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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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
Hello @Lukas Piech
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--
Thank you Both for replying!
I've used RichMatheisen-8856 solution, it works just as i wanted!
Regards,
Lukas