i have manage to make some script which delete all files and leave only 1st and 15th day.
So idea is now, that i want to leave also past month, and trigger this script in a 2 months (i will do it with task scheduller)
Actually thinking it really through you already have everything you need to catch ALL firsts and fifteenths from the past.
Please do yourself and others a favor and start formatting your code nicely and avoid using aliasses. That makes your code easier to read and easier to understand.
but is this going to work?
I want every 6th month to delete all and ofcourse leave past two months not removed.
So in the June 1st when i delete all, 1st and 15th files of April and May must be here.
Dont sure if this what i added will work.
Should I add this as a seperate script
If you’re not sure - test it!! Take some example files - ideally copy the original files to a test folder and test your script logic. You learn the most when you figure it out by yourself.
Since PowerShell version 3.0 you do not need this anymore: !$_.PsIsContainer . Get-ChildItem has a parameter -File or -Directory - use them if needed. You should always read the complete help for cmdlets you’re about to use - including the examples to learn how they work.
If you want to add more than 30 days you should use another unit instead of days because it’s harder to read if you have to calculate in your mind first to understand what time span it is about. You can use .AddMonths() and you can even combine 2 different units like .AddMonths(6).AddDays(15) for example.
At the end of the day it is your decission but it does not make sense for me at all. If you want to keep the last 2 month you can run the code anytime leaving the last 2 month.