Bird
0
0

You want to list all files in C:\Projects and its subfolders, but only those modified in the last 7 days. Which command achieves this?

hard📝 Application Q8 of 15
PowerShell - File and Directory Operations
You want to list all files in C:\Projects and its subfolders, but only those modified in the last 7 days. Which command achieves this?
AGet-ChildItem -Path C:\Projects -Recurse -Filter LastWriteTime -gt (Get-Date).AddDays(-7)
BGet-ChildItem -Path C:\Projects -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) -and $_.PSIsContainer -eq $false }
CGet-ChildItem -Path C:\Projects -File -Recurse -LastWriteTime (Get-Date).AddDays(-7)
DGet-ChildItem -Path C:\Projects -Recurse | Where-Object { $_.CreationTime -lt (Get-Date).AddDays(-7) }
Step-by-Step Solution
Solution:
  1. Step 1: Filter files modified in last 7 days

    Use Where-Object to check LastWriteTime greater than 7 days ago.
  2. Step 2: Exclude directories

    Check that $_.PSIsContainer is false to list only files.
  3. Step 3: Verify options

    Get-ChildItem -Path C:\Projects -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) -and $_.PSIsContainer -eq $false } correctly uses these filters; others misuse parameters or filter incorrectly.
  4. Final Answer:

    Get-ChildItem -Path C:\Projects -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) -and $_.PSIsContainer -eq $false } -> Option B
  5. Quick Check:

    Filter by LastWriteTime and exclude folders = Get-ChildItem -Path C:\Projects -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) -and $_.PSIsContainer -eq $false } [OK]
Quick Trick: Use Where-Object to filter by date and exclude folders [OK]
Common Mistakes:
  • Trying to filter by LastWriteTime directly in Get-ChildItem
  • Not excluding folders
  • Using CreationTime instead of LastWriteTime

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes