Eu tive o mesmo problema e escrevi essa função para excluir o log de eventos.
Function Remove-PowerShellEventLog {
Write-ToLog -Message 'Remove the PowerShell event log'
# Function constants
$PowerShellKey = 'SYSTEM\CurrentControlSet\Services\EventLog\Windows PowerShell'
$Admins = 'BUILTIN\Administrators'
$ReadWriteSubTree = [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree
$TakeOwnership = [System.Security.AccessControl.RegistryRights]::TakeOwnership
$ChangePermissions = [System.Security.AccessControl.RegistryRights]::ChangePermissions
# Define a C# type using P/Invoke and add it
# Code borrowed from https://www.remkoweijnen.nl/blog/2012/01/16/take-ownership-of-a-registry-key-in-powershell/
$Definition = @"
using System;
using System.Runtime.InteropServices;
namespace Win32Api
{
public class NtDll
{
[DllImport("ntdll.dll", EntryPoint="RtlAdjustPrivilege")]
public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled);
}
}
"@
Add-Type -TypeDefinition $Definition -PassThru
# Enable SeTakeOwnershipPrivilege
$Res = [Win32Api.NtDll]::RtlAdjustPrivilege(9, $True, $False, [ref]$False)
# Open the registry key with Take Ownership rights and change the owner to Administrators
$Key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("$PowerShellKey\PowerShell", $ReadWriteSubTree, $TakeOwnership)
$Acl = $Key.GetAccessControl()
$Acl.SetOwner([System.Security.Principal.NTAccount]$Admins)
$Key.SetAccessControl($Acl)
# Re-open the key with Change Permissions rights and grant Administrators Full Control rights
$Key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("$PowerShellKey\PowerShell", $ReadWriteSubTree, $ChangePermissions)
$Acl = $Key.GetAccessControl()
$Rule = New-Object System.Security.AccessControl.RegistryAccessRule ($Admins, 'FullControl', 'Allow')
$Acl.SetAccessRule($Rule)
$Key.SetAccessControl($Acl)
# Remove the parent and subkeys
Remove-Item -Path "HKLM:\$PowerShellKey" -Force -Recurse
# Restart the Event Log service to enforce changes
Restart-Service EventLog -Force
}