I have a command line argument script written in PowerShell which accepts server name from the task scheduler. However my requirement is to execute the script when the SQL server is restarted, hence I have attached the PowerShell script to the event 17069. But I am unable to dynamically pass the event source which would be the server name in this case.
Below is argument section of the task scheduler job
-Command "& 'D:\SQLJobs\PS\readErrorLogFile.ps1' '$(Source)'"
$(Source) does not pick up the event source from event view while firing the powerShell. Can you please let me know how to pick up the event source.
As suggested in the comments I have updated my task scheduler job with below XML branch
<ValueQueries>
<Value name="server">Source</Value>
</ValueQueries>
The Above script has been inserted in <EventTrigger>
Branch.
Below is PowerShell CMD line input script.
param (
[string]$server
)
Kindly let me know what needs to be mentioned in the argument section of the task scheduler job as $(server)
displays null in the script.