I have a requirement to exclude files based on year, country name and last modified date from that particular year and rest files from that particular year and the country moved to an archive folder
for an example
- SS_MM_Master_finland_2018.xlsx last modified date 27/06/2018 19:00.
- SS_MM_Master_finland_2017.xlsx last modified date 27/06/2017 19:00.
in this case, same country and year is different in the file name so that particular year- last modified date would be excluded so both the files will be excluded
wants to know if someone can give a small example based on their experience...not necessary to be from above example or any multiple exclude rule or anything contribution would be appreciated
funny thing is that i have only single file excluder statement and do not know the multiple file excluder rule based on file name, Any example appericiated
I have only single file exclude statement
$sourcedir = 'C:\Test\Country'
$destdir = 'C:\Test\Country\Archive'
Get-ChildItem -File -Path $sourcedir |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -Skip 1 |
Move-Item -Destination $destdir -force
thanks
I post this as an answer as I don't have the characters to do it as comment. Let me see if I understand this.
You then have an export of the files like:
And then you can go with an foreach with if like:
I believe you can understand the concept behind this code. You can replace the Italy with a variable that you can do with Read-Host that goes for all your conditions on the if statement and then if those are true move the file to the other folder.
Hope this answer will help you.