Hallo Community,
ich suche eine eine Möglichkeit Events einfach in ein anderes Event zu schreiben.
Ziel ist es das Event 5156 zu sichern, allerdings in eine gemeinsames Protokoll, dass ich ebenfalls nach Größe löschen kann.
Meine Idee wäre hier folgende:
cls
$message = Get-EventLog "Security" -newest 100 | Where-Object {$_.EventID -eq 5157} | Format-List -property "Message"
$message.ToString()
echo $message
$evt=new-object System.Diagnostics.EventLog("Application")
$evt.Source="MyEvent"
$infoevent=[system.Diagnostics.EventLogEntryType]::Information
$evt.WriteEntry($message,$infoevent,70)
Leider habe ich hier einen Fehler bekommen, da es sich bei der Variable $message um ein Array handelt.
Als Ausgabe in das neue Event bekomme ich dann:
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Daraufhin habe ich versucht das array einfach zu konvertieren. was mir allerdings nicht gelingt .... Hier mein QUelltext
cls
[array]$message = Get-EventLog "Security" -newest 100 | Where-Object {$_.EventID -eq 5157} | Format-List -property "Message"
$test=[string]
for ($i=0; $i -le $message.Length – 1; $i++){
$test = $test + $message[$i]
}
echo $test
$evt=new-object System.Diagnostics.EventLog("Application")
$evt.Source="MyEvent"
$infoevent=[system.Diagnostics.EventLogEntryType]::Information
$evt.WriteEntry($message ,$infoevent,70)
Ich arbeite mit dem PowerGui Skript Editor, er zeigt mit an, dass diese Variable auch gefüllt ist.
Danke vorab
Gruß