Open in the explorer

Turn on PowerShell Script Block Logging

Activer la journalisation de blocs de scripts PowerShell

Type
Computer and user
GPO path
Computer Configuration › Policies › Administrative Templates › Windows Components › Windows PowerShell User Configuration › Policies › Administrative Templates › Windows Components › Windows PowerShell FR: Configuration ordinateur › Stratégies › Modèles d'administration › Composants Windows › Windows PowerShellFR: Configuration utilisateur › Stratégies › Modèles d'administration › Composants Windows › Windows PowerShell
Supported on
At least Microsoft Windows 7 or Windows Server 2008 family FR: Au moins Microsoft Windows 7 ou famille Windows Server 2008
ADMX file
PowerShellExecutionPolicy.admx
Internal name
PowerShellExecutionPolicy/EnableScriptBlockLogging

Explanation

This policy setting enables logging of all PowerShell script input to the Microsoft-Windows-PowerShell/Operational event log. If you enable this policy setting,
Windows PowerShell will log the processing of commands, script blocks, functions, and scripts - whether invoked interactively, or through automation.

If you disable this policy setting, logging of PowerShell script input is disabled.

If you enable the Script Block Invocation Logging, PowerShell additionally logs events when invocation of a command, script block, function, or script
starts or stops. Enabling Invocation Logging generates a high volume of event logs.

Note: This policy setting exists under both Computer Configuration and User Configuration in the Group Policy Editor. The Computer Configuration policy setting takes precedence over the User Configuration policy setting.

French text from Windows 11 26H2

Ce paramètre de stratégie active la journalisation de toutes les entrées de scripts PowerShell dans le journal des événements Microsoft-Windows-PowerShell/Operationnal. Si vous activez ce paramètre de stratégie,
Windows PowerShell enregistrera le traitement des commandes, les blocs de scripts, les fonctions et les scripts - qu'ils soient appelés de manière interactive ou par le biais de l'automatisation.

Si vous désactivez ce paramètre de stratégie, la journalisation des entrées de scripts PowerShell est désactivée.

Si vous activez la journalisation des appels de blocs de scripts, PowerShell enregistre également les événements de début et de fin d'appel de commandes, de blocs de scripts, de fonctions ou de scripst
L'activation de la journalisation des appels génère un volume élevé de journaux d'événements.

Remarque : ce paramètre de stratégie se trouve sous Configuration ordinateur et Configuration utilisateur dans l'éditeur de stratégie de groupe. Le paramètre de stratégie de Configuration ordinateur est prioritaire sur le paramètre de stratégie de Configuration utilisateur.

Use cases

Logs the content of every PowerShell script block executed (interactive or automated) to the event log, including code decoded after obfuscation. It is one of the most useful sources for detecting "living off the land" attacks.

The log may contain passwords or secrets passed in scripts: combine it with Protected Event Logging (CMS encryption) and restrict access to the log. Invocation logging produces a high event volume.

Microsoft sources: about_Group_Policy_Settings · about_Logging_Windows

Registry

HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
Value name
EnableScriptBlockLogging
StateValue written
EnabledREG_DWORD = 1
DisabledREG_DWORD = 0

PowerShell

PowerShell commands that write to the registry what the policy would write. Values in angle brackets (<…>) must be replaced.

Writing directly to the registry bypasses Group Policy: if a GPO manages this value, it will be rewritten at the next gpupdate; otherwise the value stays in place (the "tattooing" effect). Prefer a GPO or, locally, LGPO.exe. Run PowerShell as administrator for HKLM. Some policies need a restart or gpupdate /force.

Computer (HKLM)

Enable

# Enable: PowerShellExecutionPolicy/EnableScriptBlockLogging
$k = 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
if (-not (Test-Path -Path $k)) { New-Item -Path $k -Force | Out-Null }
Set-ItemProperty -Path $k -Name 'EnableScriptBlockLogging' -Value 1 -Type DWord
# Log script block invocation start / stop events
# value not defined in the ADMX (the GPO editor usually writes 1/0)
# 1 = checked, 0 = unchecked; default state taken from the ADML
Set-ItemProperty -Path $k -Name 'EnableScriptBlockInvocationLogging' -Value 1 -Type DWord

Disable

# Disable: PowerShellExecutionPolicy/EnableScriptBlockLogging
$k = 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
if (-not (Test-Path -Path $k)) { New-Item -Path $k -Force | Out-Null }
Set-ItemProperty -Path $k -Name 'EnableScriptBlockLogging' -Value 0 -Type DWord

Revert to "Not configured"

# Revert to "Not configured": PowerShellExecutionPolicy/EnableScriptBlockLogging
$k = 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
Remove-ItemProperty -Path $k -Name 'EnableScriptBlockLogging' -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $k -Name 'EnableScriptBlockInvocationLogging' -ErrorAction SilentlyContinue

User (HKCU)

Enable

Disable

Revert to "Not configured"

Options (1)

LabelControlRegistry valueREG typeConstraints / details
Log script block invocation start / stop events:Consigner les événements de début/de fin des appels de blocs de scripts :EnableScriptBlockInvocationLoggingCheck boxbooleanEnableScriptBlockInvocationLoggingREG_DWORD
Checked: implicit: 1
Unchecked: implicit: 0

Availability