Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of log cleanup automation?
To automatically delete or archive old log files to save disk space and keep the system organized.
Click to reveal answer
beginner
In PowerShell, which cmdlet is commonly used to remove files?
The <code>Remove-Item</code> cmdlet is used to delete files or folders.
Click to reveal answer
intermediate
How can you find files older than 30 days in PowerShell?
Use Get-ChildItem with Where-Object to filter files by their LastWriteTime property, like: Get-ChildItem | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) }.
Click to reveal answer
beginner
Why is it important to test a log cleanup script before scheduling it?
To make sure it deletes only the intended files and does not remove important data by mistake.
Click to reveal answer
beginner
What PowerShell feature allows you to schedule a script to run regularly?
You can use Windows Task Scheduler to run PowerShell scripts on a schedule.
Click to reveal answer
Which PowerShell cmdlet deletes files?
ASet-Location
BGet-Content
CRemove-Item
DNew-Item
✗ Incorrect
Remove-Item deletes files or folders. The others do not delete files.
How do you select files older than 7 days in PowerShell?
A. The filter uses -gt instead of -lt, so it deletes newer files
B. Remove-Item cannot be used in a pipeline
C. Get-ChildItem does not support -Filter parameter
D. The script is missing the -Recurse flag
Solution
Step 1: Check the date comparison operator
-gt means greater than, so it selects files newer than 15 days, opposite of intended.
Step 2: Confirm correct operator for old files
To delete files older than 15 days, use -lt (less than) with AddDays(-15).
Final Answer:
The filter uses -gt instead of -lt, so it deletes newer files -> Option A
Quick Check:
Older files need -lt, not -gt [OK]
Hint: Use -lt for files older than a date, not -gt [OK]
Common Mistakes:
Using -gt instead of -lt for filtering old files
Thinking Remove-Item can't be piped
Assuming -Filter is unsupported by Get-ChildItem
5. You want to automate deleting log files older than 10 days from C:\Logs and log the deleted filenames to deleted_logs.txt. Which script correctly does this?