I have a folder containing 5 files.
I want to skip the first latest file and want the name of second latest file. How I can do this using PowerShell commands?
I have a folder containing 5 files.
I want to skip the first latest file and want the name of second latest file. How I can do this using PowerShell commands?
Copyright © 2021 Jogjafile Inc.
Do this:
This uses
Get-ChildItemto return just files.It then uses the
Sort-Objectcmdlet to sort them by theirLastAccessTimevalue in Descending order (so the most recently accessed is at the top).It then uses
Select-Objectto skip the 1st item in the collection (the most recently accessed) and return just the first result of the remaining items (i.e the second most recently accessed).Finally the
-ExpandPropertyparameter ofSelect-Objectis used to return just theNameproperty as its string type.