Windows Components › Windows PowerShell
Turn on PowerShell Script Block Logging
Supported on At least Microsoft Windows 7 or Windows Server 2008 family
What it does
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.
What it writes
- Hive
- HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER
- Registry key
Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging- Value name
EnableScriptBlockLogging- When enabled
- DWORD 1
- When disabled
- DWORD 0
In Intune
Native Intune setting: Yes — Policy CSP
./Device/Vendor/MSFT/Policy/Config/WindowsPowerShell/TurnOnPowerShellScriptBlockLoggingWindowsPowerShell on Microsoft LearnADMX-backed: Windows ships this template, so it is set with the template's own values, without an import.Windows builds listed: 10.0.17134../User/Vendor/MSFT/Policy/Config/WindowsPowerShell/TurnOnPowerShellScriptBlockLoggingWindowsPowerShell on Microsoft LearnADMX-backed: Windows ships this template, so it is set with the template's own values, without an import.Windows builds listed: 10.0.17134.
From Microsoft's Policy CSP DDF files (DDF v2 Files, February 2026), read 18 Oct 2026.
Security baselines
Microsoft's Windows 11 v26H2 Security Baseline v2 sets this to Enabled, in its GPO “MSFT Windows 11 26H2 - Computer”.
- Policy value EnableScriptBlockLogging
- Sets EnableScriptBlockLogging to 1 (REG_DWORD).
- Log script block invocation start / stop events
- Deletes the EnableScriptBlockInvocationLogging value, so nothing is set there and the product's own default applies.
Read from the registry.pol files in the baselines' GPO backups, downloaded from Microsoft's Security Compliance Toolkit. All baselines
Options
| Option | Type | Registry value | Allowed values |
|---|---|---|---|
| Log script block invocation start / stop events | Checkbox | EnableScriptBlockInvocationLogging |
On (1) or off (0) |
Configure and deploy
Choose a state and the option values; the output below is generated from the template for exactly that.
Enabled · Computer · template defaults
Registry file (.reg)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging]
"EnableScriptBlockInvocationLogging"=dword:00000001
"EnableScriptBlockLogging"=dword:00000001
PowerShell
$ErrorActionPreference = 'Stop'
function Set-RegistryValue {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name,
[Parameter(Mandatory = $true)][string] $PropertyType,
[Parameter(Mandatory = $true)][object] $Value
)
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -Path $Path -Force | Out-Null
}
New-ItemProperty -LiteralPath $Path -Name $Name -PropertyType $PropertyType -Value $Value -Force | Out-Null
}
function Remove-RegistryValue {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name
)
if (Test-Path -LiteralPath $Path) {
Remove-ItemProperty -LiteralPath $Path -Name $Name -Force -ErrorAction SilentlyContinue
}
}
function Clear-RegistryKeyValues {
param(
[Parameter(Mandatory = $true)][string] $Path
)
if (-not (Test-Path -LiteralPath $Path)) {
return
}
foreach ($propertyName in (Get-Item -LiteralPath $Path).Property) {
Remove-ItemProperty -LiteralPath $Path -Name $propertyName -Force -ErrorAction SilentlyContinue
}
}
# Policy: Turn on PowerShell Script Block Logging
# Name: EnableScriptBlockLogging
# Scope: Machine
# State: Enabled
# Source: PowerShellExecutionPolicy.admx
Set-RegistryValue -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockLogging' -PropertyType 'DWord' -Value 1
Set-RegistryValue -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockInvocationLogging' -PropertyType 'DWord' -Value 1
These deployment candidates come from the ADMX template; they are separate from the native CSP mapping above.
- The OMA-URI is an inferred ADMX-backed Policy CSP candidate derived from the source ADMX file name and policy name.
- Some Microsoft policies use built-in Policy CSP pages whose area names don't match the ADMX file name, so verify the candidate against Microsoft Learn before deployment.
- The generated payload is incomplete because one or more ADMX element values were not supplied: EnableScriptBlockInvocationLogging
ADMX profile candidate (OMA-URI)
./Device/Vendor/MSFT/Policy/Config/ADMX_PowerShellExecutionPolicy/EnableScriptBlockLoggingIntune remediation scripts
Detection
$ErrorActionPreference = 'Stop'
$reasons = [System.Collections.Generic.List[string]]::new()
function Test-RegistryValueExists {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name
)
if (-not (Test-Path -LiteralPath $Path)) {
return $false
}
return $null -ne (Get-ItemProperty -LiteralPath $Path -Name $Name -ErrorAction SilentlyContinue)
}
function Test-RegistryValueEquals {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name,
[Parameter(Mandatory = $true)][string] $Kind,
[Parameter(Mandatory = $true)][object] $Expected
)
if (-not (Test-Path -LiteralPath $Path)) {
return $false
}
$valueObject = Get-ItemProperty -LiteralPath $Path -Name $Name -ErrorAction SilentlyContinue
if ($null -eq $valueObject) {
return $false
}
$actual = $valueObject.$Name
switch ($Kind) {
'String' { return [string]$actual -ceq [string]$Expected }
'ExpandString' { return [string]$actual -ceq [string]$Expected }
'DWord' { return [uint32]$actual -eq [uint32]$Expected }
'QWord' { return [uint64]$actual -eq [uint64]$Expected }
'MultiString' {
$actualArray = @($actual)
$expectedArray = @($Expected)
if ($actualArray.Count -ne $expectedArray.Count) { return $false }
for ($index = 0; $index -lt $actualArray.Count; $index++) {
if ([string]$actualArray[$index] -cne [string]$expectedArray[$index]) { return $false }
}
return $true
}
'Binary' {
$actualArray = [byte[]]$actual
$expectedArray = [byte[]]$Expected
if ($actualArray.Length -ne $expectedArray.Length) { return $false }
for ($index = 0; $index -lt $actualArray.Length; $index++) {
if ($actualArray[$index] -ne $expectedArray[$index]) { return $false }
}
return $true
}
default { return [string]$actual -ceq [string]$Expected }
}
}
# Policy: Turn on PowerShell Script Block Logging
# Name: EnableScriptBlockLogging
# Scope: Machine
# State: Enabled
# Source: PowerShellExecutionPolicy.admx
$isMatch = Test-RegistryValueEquals -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockLogging' -Kind 'DWord' -Expected 1
if (-not $isMatch) {
$reasons.Add('Value mismatch: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\EnableScriptBlockLogging') | Out-Null
}
$isMatch = Test-RegistryValueEquals -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockInvocationLogging' -Kind 'DWord' -Expected 1
if (-not $isMatch) {
$reasons.Add('Value mismatch: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\EnableScriptBlockInvocationLogging') | Out-Null
}
if ($reasons.Count -eq 0) {
Write-Output 'Compliant'
exit 0
}
$reasons | ForEach-Object { Write-Output $_ }
exit 1
Remediation
$ErrorActionPreference = 'Stop'
function Set-RegistryValue {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name,
[Parameter(Mandatory = $true)][string] $PropertyType,
[Parameter(Mandatory = $true)][object] $Value
)
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -Path $Path -Force | Out-Null
}
New-ItemProperty -LiteralPath $Path -Name $Name -PropertyType $PropertyType -Value $Value -Force | Out-Null
}
function Remove-RegistryValue {
param(
[Parameter(Mandatory = $true)][string] $Path,
[Parameter(Mandatory = $true)][string] $Name
)
if (Test-Path -LiteralPath $Path) {
Remove-ItemProperty -LiteralPath $Path -Name $Name -Force -ErrorAction SilentlyContinue
}
}
function Clear-RegistryKeyValues {
param(
[Parameter(Mandatory = $true)][string] $Path
)
if (-not (Test-Path -LiteralPath $Path)) {
return
}
foreach ($propertyName in (Get-Item -LiteralPath $Path).Property) {
Remove-ItemProperty -LiteralPath $Path -Name $propertyName -Force -ErrorAction SilentlyContinue
}
}
# Policy: Turn on PowerShell Script Block Logging
# Name: EnableScriptBlockLogging
# Scope: Machine
# State: Enabled
# Source: PowerShellExecutionPolicy.admx
Set-RegistryValue -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockLogging' -PropertyType 'DWord' -Value 1
Set-RegistryValue -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name 'EnableScriptBlockInvocationLogging' -PropertyType 'DWord' -Value 1
History 3 retained releases
- 22H2 · 1.015 Jul 2024
- Already present in the first release ChangeIntel keeps.
2 later releases left it unchanged.
Template
- Internal name
EnableScriptBlockLogging- Namespace
Microsoft.Policies.PowerShell- Template file
PowerShellExecutionPolicy.admx- Release
- Windows 11 23H2 · 1.0 · file set
d784d0ea5f14a680…
Definition, editor controls and support
Definition
<policy class="Both" displayName="$(string.EnableScriptBlockLogging)" explainText="$(string.EnableScriptBlockLogging_Explain)" key="Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" name="EnableScriptBlockLogging" presentation="$(presentation.EnableScriptBlockLogging)" valueName="EnableScriptBlockLogging" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
<parentCategory ref="Microsoft.Policies.PowerShell:PowerShell" />
<supportedOn ref="Microsoft.Policies.PowerShell:SUPPORTED_WIN7" />
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
<elements>
<boolean id="EnableScriptBlockInvocationLogging" valueName="EnableScriptBlockInvocationLogging" />
</elements>
</policy>Editor controls
<presentation id="EnableScriptBlockLogging" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
<checkBox refId="EnableScriptBlockInvocationLogging">Log script block invocation start / stop events:</checkBox>
</presentation>Supported platforms and category
Microsoft.Policies.PowerShell:category:PowerShell
<category displayName="$(string.PowerShell)" name="PowerShell" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
<parentCategory ref="Microsoft.Policies.Windows:WindowsComponents" />
</category>
Microsoft.Policies.PowerShell:definition:SUPPORTED_WIN7
<definition displayName="$(string.SUPPORTED_WIN7)" name="SUPPORTED_WIN7" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions" />
Microsoft.Policies.Windows:category:WindowsComponents
<category displayName="$(string.WindowsComponents)" explainText="$(string.WindowsComponents_Help)" name="WindowsComponents" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions" />
Microsoft.Policies.PowerShell:category:PowerShell
<category displayName="$(string.PowerShell)" name="PowerShell" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
<parentCategory ref="Microsoft.Policies.Windows:WindowsComponents" />
</category>
<strings><string id="Microsoft.Policies.PowerShell:PowerShell">Windows PowerShell</string></strings>
Microsoft.Policies.PowerShell:definition:SUPPORTED_WIN7
<definition displayName="$(string.SUPPORTED_WIN7)" name="SUPPORTED_WIN7" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions" />
<strings><string id="Microsoft.Policies.PowerShell:SUPPORTED_WIN7">At least Microsoft Windows 7 or Windows Server 2008 family</string></strings>
Microsoft.Policies.Windows:category:WindowsComponents
<category displayName="$(string.WindowsComponents)" explainText="$(string.WindowsComponents_Help)" name="WindowsComponents" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions" />
<strings><string id="Microsoft.Policies.Windows:WindowsComponents">Windows Components</string><string id="Microsoft.Policies.Windows:WindowsComponents_Help">Contains settings for operating system components.</string></strings>