I am trying to empty the contents of a list of folders that I have in a text file leaving the empty folder itself alone, using these following commands
$Targetfolder = "\\a\b\test
$includefiles = "\\c\list.txt"
Remove-Item $TargetFolder\* -Force -Recurse -Include (Get-Content $includefiles) -Verbose
It is removing an empty directory but not directories which have contents I also tried
Get-ChildItem $TargetFolder -Include (Get-Content $includefiles) -Recurse | ForEach {$_.Delete()}
Shows directory not empty error with this
Please help!!