Bird
0
0

What will be the result of running this PowerShell command?

medium📝 Command Output Q4 of 15
PowerShell - Automation Patterns
What will be the result of running this PowerShell command?
Get-ChildItem -Path 'D:\AppLogs' -Filter '*.txt' | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-5) } | Remove-Item -WhatIf
AShows an error because -WhatIf is not valid with Remove-Item
BDeletes all .txt files in D:\AppLogs immediately
CLists the files that would be deleted without actually deleting them
DRenames files older than 5 days instead of deleting
Step-by-Step Solution
Solution:
  1. Step 1: Understand -WhatIf parameter

    -WhatIf simulates the command without making changes.
  2. Step 2: Analyze the command

    It filters .txt files older than 5 days and simulates deletion.
  3. Final Answer:

    Lists the files that would be deleted without actually deleting them -> Option C
  4. Quick Check:

    -WhatIf previews actions [OK]
Quick Trick: -WhatIf previews deletions without changes [OK]
Common Mistakes:
  • Assuming files are deleted with -WhatIf
  • Believing -WhatIf causes errors
  • Thinking files are renamed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes