i have created a task in Taskplaner that, whenever a new log-entry got created, it executes the following PS-script that should write the newly created eventlog-entry in a csv-file on storage.
$date = Get-Date
$pdate = Get-Date -UFormat %Y-%d-%m
$Name = 'Microsoft-Windows-TerminalServices-Gateway/Operational'
$Log = [System.Diagnostics.EventLog]$Name
$Action = {
# get the original event entry that triggered the event
$entry = $event.SourceEventArgs.Entry
# do something based on the event
$entry | select TimeCreated, Id, LevelDisplayName, message | Export-Csv -Path c:\TestLog.csv -append
Unfortunately the file did not get updated even the task scheduler said that the script was called and no error happend. Task is run as Domainadmin and user has write access to file. Starting the script manually works, even no output is written as no logitem-object exists when running manually.
The script seems to work fine when using it manually (as it is possible to test at all)
Can someone pls. point me to the mistake i have made?
Thanks.
Here are the settings in Task Scheduler