Powershell script to get latest changed files from a folder

Here is the command to list latest modified files from a folder.

 Get-ChildItem -Path  c:\temp  | Sort-Object LastAccessTime -Descending | Select-Object -First 1

The above command will output the latest changed/modified files from c:\temp location.

If you need to get the result to a variable

 $latest =Get-ChildItem -Path  c:\temp  | Sort-Object LastAccessTime -Descending | Select-Object -First 1

If you need only the files with zip extension.

$latestzip = Get-ChildItem -Path c:\temp -filter *.zip | Sort-Object LastAccessTime -Descending | Select-Object -First 1

Comments