Last file in folder, wrong output This topic contains 4 replies, has 4 voices, and was last updated by Maarten Vekens 1 year, 2 months ago. Author Posts August 6, 2015 at 5:19 am #28225 Maarten VekensParticipant When I perform this command on the command line, I receive the correct response $Outputfiles = Get-ChildItem 'D:\TST\log\input' -Recurse | where-object LastWriteTime | select -First 1 When I do this in a script I always receive the same result, even there are new files. Any idea? August 6, 2015 at 5:27 am #28226 Richard SiddawayModerator I'm a little puzzled why you're using where-object. I'd have thought if you wanted the last file in the folder you would sort on LastWriteTime rather than just test it exists August 6, 2015 at 5:44 am #28227 Wilfredo PerezParticipant Can we see the code – please August 6, 2015 at 7:04 am #28230 Matt McNabbParticipant It seems the OP has assumed that the LastWriteTime property means "this is the last file that was written to in the folder." If you just want the most recently written file, use Sort-Object instead of Where-Object: Get-ChildItem 'D:\TST\log\input' -Recurse -File | sort lastwritetime -Descending | select -First 1 August 6, 2015 at 11:59 pm #28261 Maarten VekensParticipant thank you! the problem was caused due to the fact that after I moved the file from another location the modify time was not changed. Author Posts You must be logged in to reply to this topic.