I cannot properly format my select-string so that I can use mulitple patterns. I am also trying to espcape the \'s in my pattern. Its using a directory path.
These are the patterns I need to search for:
Successfully FTPed file [\\BATCH1\TO\DENIAL.TXT
Successfully FTPed file [\\BATCH1\TO\NEWORIGIN.TXT
Successfully FTPed file [\\BATCH1\TO\ORIGIN.TXT
Successfully FTPed file [\\BATCH1\TO\Ed.TXT
This code is working for just a single pattern search.
Get-ChildItem -Filter FTP_Outbound*.* -Path $rootFolder| Where-Object {$_.LastWriteTime -gt (get-date).AddDays(-.5)}| Select-String -pattern ([regex]::Escape('Successfully FTPed file [\\BATCH1\CFGP\TO\DENIAL.TXT'))| % {
Copy-Item -Path $_.Path -Destination 'c:\Temp'
}
In the end, I would like it to both copy the file to the C:\Temp, and display the line it found in the file within the powershell window.
SAMPLE DATA:
[11:18:24 PM] Begin SFTP File \\BATCH1\TO\BRRef[20190724202940].txt To BRRef.txt
[11:18:44 PM] Successfully FTPed file [\\BATCH1\TO\DENIAL.TXT[20190724194428]] to [\DENIAL.TXT]
[11:18:44 PM] Successfully FTPed file [\\BATCH1\TO\NEWORIGIN.TXT[20190724194428]] to [\NEWORIGIN.TXT]
[11:18:44 PM] Successfully FTPed file [\\BATCH1\TO\ORIGIN.TXT[20190724194428]] to [\ORIGIN.TXT]
[11:18:48 PM] Successfully FTPed file [\\BATCH1\TO\BRRef[20190724202940].txt] to [\BRRef.txt]
[11:18:48 PM] Update ProducedFile Set DeliveredFileName='BRRef.txt' Where CreateID=7710395
[11:18:48 PM] Successfully backed up file as :\\BATCH1\TO_BACKUP\BRRef[20190724202940]_20190724_231848.txt
FILE #2. [Ed.TXT[20190724194428]], begin FTP at [11:19:05 PM]
Destination file name is: Ed.TXT[20190724194428]
After replaceing [], destination file name become: Ed.TXT
[11:19:05 PM] Begin SFTP File \\BATCH1\TO\Ed.TXT[20190724194428] To Ed.TXT
[11:19:07 PM] Successfully FTPed file [\\BATCH1\TO\Ed.TXT[20190724194428]] to [\Ed.TXT]
[11:19:07 PM] Update ProducedFile Set DeliveredFileName='Ed.TXT' Where CreateID=7710363
[11:19:07 PM] Successfully backed up file as :\\BATCH1\TO_BACKUP\Ed_20190724_231907.TXT[20190724194428]
Successfully FTPed fileAND contain one ofDENIAL.TXT|NEWORIGIN.TXT|ORIGIN.TXT|Ed.TXTbut NOTBRRef[20190724202940].txtorEd_20190724_231907.TXT? is that correct?