I have a PS script which deletes the folders and files from a particular path older than 15 days. I want to exclude "_tasks" folder and its contents from getting deleted but the scripts deletes the files and folders inside it even when I have provided -Exclude property to exclude _tasks folder and its contents.
Below is the script I am using.
How can I exclude the _tasks folder and its sub-folders and files from getting deleted?
Get-ChildItem –Path "F:\Suraj\Garbage" -Recurse -Exclude "__tasks" | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-15))} | Remove-Item -Force -Recurse
Below images shows that the files on the left side were deleted inside the _tasks folders. I don't want them to be deleted. Any suggestion for same would be helpful.