Hi, @Loganathan R
Thank you for posting in Microsoft Q&A forum.
Please try the below script, it removes all the txt file under c:\temp, and log all the deleted files to the test.log.
$logFile = 'c:\temp\test.log' $files = get-childitem -path C:\temp -file -recurse -include *.txt ($files).fullname >> $logFile $files | Remove-Item
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.