0
0
PowerShellscripting~20 mins

Remove-Item in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Remove Files Using Remove-Item in PowerShell
📖 Scenario: You are managing files on your computer. Sometimes, you need to delete old or unwanted files to keep your folders clean and organized.
🎯 Goal: Learn how to use the Remove-Item command in PowerShell to delete specific files from a folder.
📋 What You'll Learn
Create a list of file names as strings
Set a variable for the folder path
Use a loop to remove each file using Remove-Item
Print a message confirming each file removal
💡 Why This Matters
🌍 Real World
Cleaning up old or temporary files is a common task to keep computers organized and free of clutter.
💼 Career
System administrators and IT professionals often automate file management tasks using PowerShell scripts like this.
Progress0 / 4 steps
1
Create a list of files to delete
Create a variable called filesToDelete and assign it an array with these exact file names as strings: "old_report.txt", "temp_data.csv", "notes.docx".
PowerShell
Need a hint?

Use @() to create an array in PowerShell.

2
Set the folder path variable
Create a variable called folderPath and set it to the string "C:\\Users\\Public\\Documents".
PowerShell
Need a hint?

Remember to escape backslashes in strings or use double backslashes.

3
Remove each file using Remove-Item
Write a foreach loop using the variable file to go through filesToDelete. Inside the loop, use Remove-Item with the path combining folderPath and file. Use -ErrorAction SilentlyContinue to avoid errors if a file does not exist.
PowerShell
Need a hint?

Use double quotes to combine variables inside strings for the file path.

4
Print confirmation for each removed file
Inside the foreach loop, after Remove-Item, add a Write-Output statement that prints: "Removed file: $file".
PowerShell
Need a hint?

Use Write-Output to print messages in PowerShell.