Piping powershell messages to Write-EventLog
- by Richard
I have a powershell script that runs a custom cmdlet. It is run by Task Scheduler and I want to log what it does.
This is my current crude version:
Add-PsSnapIn PianolaCmdlets
Write-EventLog -LogName "Windows Powershell" -Source "Powershell" -Message "Starting Update-EbuNumbers" -EventId 0
Get-ClubMembers -HasTemporaryEbuNumber -show all | Update-EbuNumbers -Verbose
Write-EventLog -LogName "Windows Powershell" -Source "Powershell" -Message "Finished Update-EbuNumbers" -EventId 0
What I would like to do is log the output of my custom cmdlet. Ideally I'd like to create different types of event log entries based on whether it was a warning or a verbose message.
Update: I don't want to log the return value of the commandlet. The Update-EbuMembers cmdlet does not return an object. I want to log any verbose messages written by WriteVerbose and I want to log errors created by ThrowTerminatingError.