Created
August 19, 2022 16:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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