Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q13 of 15
PowerShell - Automation Patterns
What will be the output of this PowerShell script?
Get-ChildItem -Path 'C:\Logs' -Filter '*.log' | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -WhatIf
AThrows an error because Remove-Item cannot be piped
BLists all .log files older than 7 days and deletes them
CDeletes all .log files regardless of age
DShows which .log files older than 7 days would be deleted without deleting
Step-by-Step Solution
Solution:
  1. Step 1: Understand the pipeline

    The script finds .log files older than 7 days using Get-ChildItem and Where-Object.
  2. Step 2: Analyze Remove-Item with -WhatIf

    -WhatIf shows what would happen without deleting files, so no files are removed.
  3. Final Answer:

    Shows which .log files older than 7 days would be deleted without deleting -> Option D
  4. Quick Check:

    -WhatIf shows actions without executing [OK]
Quick Trick: Remove-Item -WhatIf previews deletion without removing files [OK]
Common Mistakes:
  • Thinking files are deleted with -WhatIf
  • Assuming Remove-Item cannot be piped
  • Confusing filter for files newer than 7 days

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes