I am trying to get the below PowerShell script to work using Task Scheduler. The problem is that it wont delete any files.
When I run it manually it needs a confirma
In my opinion Remove-Item -Path "C:\Temp\FolderToDelete" -Confirm:$false -Force
should just work without any prompt. But it doesn't.
To delete the whole folder and everything in it without any prompt, I had to use GCI and go up a level. So instead of:
Get-ChildItem -Path "C:\Temp\FolderToDelete" | Remove-Item -Recurse -Confirm:$false -Force
Which deletes everything inside FolderToDelete, but not the parent folder.
To delete the parent folder and everything in it without a prompt, I did:
Get-ChildItem -Path "C:\Temp\" -Directory -Filter "FolderToDelete" | Remove-Item -Recurse -Confirm:$false -Force
Note the trailing '\' in -Path C:\Temp\
.
HTH