I am making a Script that has to delete all the files in a directory that do not match the creation date with the year in which it is executed, that is, if I execute it in 2017 it deletes everything that has not been created that year.
I have managed to get the year, but I don't know how to delete the files:
$yearOs = Get-Date -Format yyyy
$yearItems = Get-ChildItem E:\Backup\ | get-date -Format yyyy
foreach ($i in $yearItems) {
if ($i -ne $yearOs) {
echo $i # esto da cualquier fecha que no sea el año en el que se ejecuta
}
}
I have also thought about using the command forfiles
but I already told you that in PS I am a little green.