Script to delete files based on list and generate results file

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
}

So what is the question?
Also if you already have a list of items to remove, I’m assuming the full paths you would just past $fileList.FullPath to Remove-Item

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.