How to find a file name

Hello. I am new to PowerShell, and I hope someone can help me…

I Have a file on my server that I need to copy every night for backup. I can do the copy with a simple batch file, but the directory has 5 files from 5 previous days, so I cannot just copy all of the files daily or I will get duplicates, so I need to find the current file and do a network copy of only one file to a new location

The file name is complicated as you can see below. the current date is always embedded as you can see in the example below - 20220209


Can this be done with PowerShell? if so can someone help me do this?

thanks for any help or pointers


Welcome to the forum. :wave:t4:

This can easily be done with PowerShell. :wink:

Since we do not provide ready to use code or solutions on request - what kind of help do you need? If you already have code you just got stuck with please share it here and we will try to help you further.

Regardless of that - you actually do not need a script you could use robocopy for such a kind of task. With the option \maxage:<n> you can specify to include only files with a maximum age of days.


robocopy /?

you can display the help for robocopy in a console or you read it online: