Bird
0
0

You want to enable script block logging only for scripts running under a specific user account without affecting others. Which approach is best?

hard📝 Best Practice Q15 of 15
PowerShell - Scripting Best Practices
You want to enable script block logging only for scripts running under a specific user account without affecting others. Which approach is best?
ASet the EnableScriptBlockLogging registry key under HKLM for all users
BModify the PowerShell profile script to log commands manually
CUse Group Policy to enable script block logging for all users
DSet the EnableScriptBlockLogging registry key under HKCU for that user
Step-by-Step Solution
Solution:
  1. Step 1: Understand scope of script block logging

    Built-in script block logging is a machine-wide feature configured under HKLM or Group Policy, affecting all users.
  2. Step 2: Identify per-user alternative

    HKCU does not enable script block logging (as it requires HKLM). Modifying the user's PowerShell profile to manually log commands (e.g., Start-Transcript) achieves per-user logging without affecting others.
  3. Final Answer:

    Modify the PowerShell profile script to log commands manually -> Option B
  4. Quick Check:

    Per-user logging = profile script [OK]
Quick Trick: Use PowerShell profile for per-user command logging [OK]
Common Mistakes:
  • Using HKLM or Group Policy which affects all users
  • Setting HKCU key (does not enable built-in logging)
  • Assuming built-in logging supports per-user config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes