Skip to content

Instantly share code, notes, and snippets.

@rrrix
Created August 19, 2022 16:17
Show Gist options
  • Save rrrix/d7bf2e3749f5bac34d1761546e006c79 to your computer and use it in GitHub Desktop.
Save rrrix/d7bf2e3749f5bac34d1761546e006c79 to your computer and use it in GitHub Desktop.
Enable Script Block Logging using Windows Registry - corrected from https://adamtheautomator.com/powershell-logging-2/#Enable_Script_Block_Logging_Using_Windows_Registry
# Correctly formatted script content from:
# https://adamtheautomator.com/powershell-logging-2/#Enable_Script_Block_Logging_Using_Windows_Registry
function Enable-PSScriptBlockLogging
{
# Registry key
$basePath = 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
# Create the key if it does not exist
if(-not (Test-Path $basePath))
{
$null = New-Item $basePath -Force
# Create the correct properties
New-ItemProperty $basePath -Name "EnableScriptBlockLogging" -PropertyType Dword
}
# These can be enabled (1) or disabled (0) by changing the value
Set-ItemProperty $basePath -Name "EnableScriptBlockLogging" -Value "1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment