I need to find a file with a specific date in it. The problem is I never know what the date will be except "today". The date is formatted as yyyyMMddhhmm. Since it was created earlier in the day by an automated process, I need to be able to find it by ignoring the hhmm part of the date. And I can't remove the hhmm because we need to be able to run this process multiple times during the day without it erroring out. To be clear, we rarely re-run the process, but we need to have the ability for it. Hence we need to keep hhmm so the process can write new files without problems.
Here's the code I have working:
Get-ChildItem -Path "FileSystem::\\my\nas\Share\Path\" -Name "MyFiles_*.zip"
When I try to add variables for the file name, I get nothing back.
$FileDateCheck = Get-Date -Format "yyyyMMDD"
$FileName = "MyFiles_" + $FileDateCheck + "*.zip"
$ZipDestinationPath = "\\my\nas\Share\Path\"
Get-ChildItem -Path "FileSystem::\\my\nas\Share\Path\" -Name $FileName
It won't even let me use a variable for the NAS path.
There are many files with similar names, just the date being different, in this directory. I just need to target the most recent one (for the moment) but I don't want to use last created property because I want to be able to adjust for other processes in which I target the file name by date and it might be older.
Any thoughts on what I'm missing here?
Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.