I am new to PowerShell and am trying to delete folders and their contents based on an input file and would like to output a log file of what has been deleted. This is to ensure that only the items in my list got deleted. The ‘D’ drive is local to the server I am running this o and ‘Z’ is a network loca-tion. There are over 800k folders in ‘Z’ and I need to delete over 30k folders.
This is what I have so far. Thank you
if (Test-Path “D:\ArchiveTest\filelist2.txt” ) {
$fileList=Get-Content “D:\ArchiveTest\filelist2.txt”
$targetFolder = "z:\SRETestDelete"
Get-ChildItem -Path “$targetFolder” | Where Name -in $fileList | Remove-Item -verbose -Force -Recurse -Confirm:$false
}