I try to write a PS script, which will browse through the folder3 and delete child files and folders, if their CreationTime and LastWriteTime are older, than 1 month:
ls -r -force 'd:\folder1\folder2\folder3' | where {($_.fullname -like '*:\*\*\*\*') -and ($_.creationtime -le (get-date).addmonths(-1)) -and ($_.lastwritetime -le (get-date).addmonths(-1))} | sort -desc fullname | rm -force
How'd I answer "No" to all the confirmations it asks, when the folder is not empty? I only need folder deletion if it's empty.
"-Confirm:$False" or "-ErrorAction SilentlyContinue" statements do not help.