Back to Browse

MICROSOFT Windows – How to Create a File Cleanup Script in PowerShell

18 views
May 12, 2026
5:40

In this video you will learn how to create a simple file cleanup script in PowerShell on MICROSOFT Windows that deletes all .txt files from the current folder. I'll walk you step‑by‑step through writing the script in Visual Studio Code, adding a confirmation prompt with Read-Host, using Get-ChildItem with a filter and Remove-Item with -Force and -ErrorAction Stop, and wrapping the removal in try/catch to handle errors. This is perfect if you want a one-command cleanup, to customize extensions or name filters, or to reuse the pattern for other file types and directories. Keywords: PowerShell cleanup script, delete txt files, Get-ChildItem, Remove-Item, Read-Host, try/catch, VS Code. How to create a file cleanup script in PowerShell on MICROSOFT Windows? How to delete all .txt files with PowerShell on MICROSOFT Windows? Where do I run a PowerShell cleanup script on MICROSOFT Windows (VS Code or PowerShell)? 0:00 Intro — what we'll build and purpose 0:27 Goal — delete every .txt file in the current folder 0:55 Choose editor — why use Visual Studio Code 1:09 Show folder contents and current files 1:21 Add Read-Host confirmation prompt 2:17 Write the if statement and check for 'y' 2:40 Use Get-ChildItem -Filter '*.txt' and Remove-Item -Force -ErrorAction Stop 3:22 Add try/catch and user messages for success/error 3:57 Run the script (.\script.ps1) and test No vs Yes 5:07 Tips — add extensions, name filters, or further customizations 5:24 Outro — like, subscribe and next steps #PowerShell #Windows #FileCleanup #Scripting Find out more: https://www.hardreset.info/devices/microsoft/microsoft-windows/ Follow us on Instagram ► https://www.instagram.com/hardreset.info Like us on Facebook ► https://www.facebook.com/hardresetinfo/ Tweet us on Twitter ► https://twitter.com/HardResetI Support us on TikTok ► https://www.tiktok.com/@hardreset.info Use Reset Guides for many popular Apps ► https://www.hardreset.info/apps/apps/

Download

0 formats

No download links available.

MICROSOFT Windows – How to Create a File Cleanup Script in PowerShell | NatokHD