This was the discussion of last evening, which was started after we receive a similar request from a specific team. The team wanted to start this trace by themselves without involving the DBAs. One of the possibility was to run SQLDiag as a Windows service; however the requirement in hand is to run it as a SQL Agent job.
In case you wanted to read about this utility & it’s additional parameters, please refer the below page from SQL Server Books Online. The following parameter helps in the initial setup of SQLDiag.
SQLDiag.exe /E +00:20:00 /N 2 /Q /O E:\temp\SQLDiag_Output
As I tested the above script, SQLDiag utility was started & collected data for 20 minutes before stopping. Since the script was running successfully, the next step was to run it as a SQL Agent job.
I created a job on my lab instance to run SQLDiag & provided Read & Write permission to the SQL Server Agent account on the SQLDiag output folder. On the Job Step properties page, select Operating system (CmdExec) as the type & add the below script. In case of my lab environment, the SQLDiag output will be saved in E:\temp\SQLDiag_Output folder.
The default traces, system configuration files are available in the output folder. There will be an additional folder named internal present inside the output folder. The internal folder contains all the output & log files generated by SQLDiag.
Hope, this will suffice the need. Happy Learning !!