Sample Header Ad - 728x90

Using SMO from PowerShell, is there a way to state that a jobstep output file should be appended and not overwritten?

3 votes
2 answers
466 views
I deploy multiple SQL Server jobs to a fleet of servers using a PowerShell script. I can create the job steps, success fail action, and even the output file. This all works on multiple servers. What I cannot determine is how to specify that the **output file is to be appended** to instead of overwritten. The following is the section from my main script. $Job is populated in a previous step. $JobStep = new-object ('Microsoft.SqlServer.Management.Smo.Agent.JobStep') ($Job, 'MyJobStepName') $JobStep.ID = 1 $JobStep.SubSystem = 'PowerShell' $Command = 'dir d:\' $JobStep.Command = $Command $JobStep.OnSuccessAction = 'GotoNextStep' $JobStep.OnFailAction = 'GotoNextStep' $JobStep.OutputFileName = 'D:\MyJobFile.txt' $JobStep.Create() I have been using this MSDN page as a reference. I modified one of the steps using SQL Server Management Studio and traced the result. This looks promising. I can issue a SQL command after I create the jobsteps. EXEC msdb.dbo.sp_update_jobstep @job_id=N'12156dcb-c8cd-4267-901a-55175dd44960', @step_id=1 , @flags=2
Asked by datagod (7141 rep)
Apr 27, 2017, 03:43 PM
Last activity: Apr 27, 2017, 10:24 PM