I'm new to PowerShell and still trying to figure things out. I have a script that will successfully copy a file from one location to another:
Copy-Item \\ServerName01\FolderName\file_09022020_0030.txt
-Destination \\ServerName02\FolderName\file_copied.txt
How can I write the script to use a variable source file name? I want to use a variable to find today's date minus 7 days and grab the corresponding file.
EX:
Copy-Item \ServerName01\FolderName\file_[variable today minus 7]*.txt
-Destination \ServerName02\FolderName\file_copied.txt
The variable date should be in the MMDDYYYY format. The timestamp at the end of each file can be ignored so I'm guessing that's a wildcard (*)
A new file is posted each day but the file name follows a pattern:
file_09022020_0030.txt
file_09012020_0030.txt
file_08312020_0305.txt
...
file_08262020_0451.txt
file_08252020_0305.txt
file_08242020_0305.txt