Have you ever tried to remove a bulk of files from Powershell with command Get-ChildItem “Path” -Recurse | Remove-Item, but you received message:

Get-ChildItem E:\Test -Recurse | Remove-Item

The item at Microsoft.PowerShell.Core\FileSystem::E:\Test\001 has children and the Recurse parameter was not specified
If you continue, all children will be removed with the item. Are you sure you want to continue?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y")

That is a standard message where Powershell inform you that sub-folders are not empty, and some of files are stored in that sub-folders. You can simply type Y or A and press Enter, and files will be deleted. But, if you want to create “more complex” script and in add  to Task Scheduler, you need to avoid that. If you use command Get-ChildItem “Path” -Recurese | Remove-Item -Recurse and in most cases that will be enough. Sometimes, you need to add switch -Confirm:$False at the end of command, and everything will be OK.

This is one of my scripts which I use to remove *.bak, *.trn and *.log files older that 7 days.

Leave a Reply

Your email address will not be published. Required fields are marked *