I have a script that I need to write an audit event to the Windows Security log when it has completed showing the user who ran it.

I can write to any log apart from the security log.

How can I do this?

```
New-EventLog -LogName Security -Source "MyApp"
Write-EventLog -LogName Security -source "MyApp" -EntryType Information -EventId 1 -Message "Script run by X"

```

When the name is changed from Security to Application or System, it works - but, I keep getting the following when using Security:

> 
> Write-EventLog : The registry key for the log "Security" for source
>  "msevent" could not be opened. At line:1 char:1
>  + Write-EventLog -LogName Security -source "msevent" -EntryType Information -Event ...
>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  + CategoryInfo : PermissionDenied: (:) [Write-EventLog], Exception
>  + FullyQualifiedErrorId : AccessDenied,Microsoft.PowerShell.Commands.WriteEventLogCommand
> 
> 
> 

I am the admin and not sure why this happens, even after trying to modify registry security permissions.

Does anyone know how I can do this?