# Script to delete files based on list and generate results file

**URL:** <https://forums.powershell.org/t/script-to-delete-files-based-on-list-and-generate-results-file/24644>\
**Category:** PowerShell Help\
**Created:** [August 27, 2024, 9:05pm UTC](https://forums.powershell.org/t/script-to-delete-files-based-on-list-and-generate-results-file/24644 "2024-08-27T21:05:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KLee](https://avatars.discourse-cdn.com/v4/letter/k/e274bd/32.png) [@KLee](https://forums.powershell.org/u/KLee)\
**Post date:** [August 27, 2024, 9:05pm UTC](https://forums.powershell.org/t/script-to-delete-files-based-on-list-and-generate-results-file/24644/1 "2024-08-27T21:05:49Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [August 27, 2024, 9:37pm UTC](https://forums.powershell.org/t/script-to-delete-files-based-on-list-and-generate-results-file/24644/2 "2024-08-27T21:37:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [September 26, 2024, 9:38pm UTC](https://forums.powershell.org/t/script-to-delete-files-based-on-list-and-generate-results-file/24644/3 "2024-09-26T21:38:37Z")

</div>

Closed on September 26, 2024, 9:38pm UTC

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