why that complicated, use DbaTools CmdLet => Start-DbaAgentJob
How to execute agent job step in powershell?
sql-server-management-objects-smo-programming-guide
smo-object-model-namespaces
using-smo-with-powershell-to-obtain-sql-server-job-information
I want to execute a agent job step through powershell, but I am a newbie for SQL server. I read the document and have some basic understanding, but I still haven't solved the problem.
$srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server "BI-DEV-DB"
$jb = $srv.JobServer.Jobs
$jb.Start("LSD_SC") <<< This is modified according to using-smo-with-powershell-to-obtain-sql-server-job-information, but it didn't work$jp = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Agent.JobStep
$jp.OnSuccessAction(QuitWithSuccess)
$jp.OnSuccessStep(QuitWithSuccess) << I do not understand the role and usage of OnSuccessAction and OnSuccessStep, but I think these two functions are helpful to me$jr = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Agent.JobServer
$jr.Jobs.Start("LSD_SC") <<< According to my understanding, is there a start event in Microsoft.SqlServer.Management.Smo.Agent.JobServer?
Can anyone give me some help?