Get SQL Agent Job stepID Tagged: SQL Agent Job stepID This topic contains 4 replies, has 2 voices, and was last updated by M. Chalut 7 months, 1 week ago. Author Posts August 9, 2016 at 2:47 pm #49733 M. ChalutParticipant Hi again guys!!! Now this time I would like to get the SQL Agent Job stepID from powershell. I only have the StepName and I would like to get information from the Job History as follow: write-host "Name: $($job.JobSteps[$stepID].Name) RunDate: $($job.JobSteps[$stepID].LastRunDate) Status: $($job.JobSteps[$stepID].LastRunOutCome)" Can I get this information using the stepname? August 9, 2016 at 2:52 pm #49737 Don JonesKeymaster It looks like $stepID contains the step ID, doesn't it? August 9, 2016 at 3:16 pm #49743 M. ChalutParticipant Well... I have to get it somehow!! I have this working... Example: write-host "Name: $($job.JobSteps.Name) RunDate: $($job.JobSteps.LastRunDate) Status: $($job.JobSteps.LastRunOutCome)" However, in my program, the user is entering the StepName only. I tried the following: $stepID = $job.CurrentRunStep write-host "StepID = $steID" But it gives me the following: StepID = 0 (unknown) August 9, 2016 at 3:56 pm #49745 Don JonesKeymaster You'd have to query that from SQL Server. Sorry, I thought you had $stepID. I'm not sure how you'd query that – it's really a SQL Server question, not PowerShell. Again, sorry. August 16, 2016 at 2:06 pm #50603 M. ChalutParticipant I found it!! $JobStep = $Job.JobSteps[$StepName] Write-Host "Name: $($JobStep.Name) RunDate: $($JobStep.LastRunDate) Status: $($JobStep.LastRunOutCome)" Author Posts You must be logged in to reply to this topic.