Who am I ?

  • Hi,

    I run, now, my jobs with steps written in powershell.

    I would like to get informations about the current job, the current step, I am running.

    I read some topics about token (like $(ESCAPE_NONEJOBID))) but don't succeed to use it in a powershell step.

    Is'nt exist more recent method ?

    Is there some initialized variables like $host or $myinvocation where I can find these informations ?

    Thank you for your help

  • Finally I use 2 tokens.

    But I'm not sure it is the best solution.

    $myRes = Invoke-Sqlcmd -Query "Select job_id, name From msdb.dbo.sysjobs Where job_id = Convert(Uniqueidentifier,$(ESCAPE_NONE(JOBID)))"

    $myJobName = $myRes.name

    $myRes = Invoke-Sqlcmd -Query "Select job_id, step_id, step_name From msdb.dbo.sysjobsteps Where job_id = Convert(Uniqueidentifier,$(ESCAPE_NONE(JOBID))) and step_id = $(ESCAPE_NONE(STEPID))"

    $myStepName = $myRes.step_name

    Ludovic.

  • Thank you for the feedback.

    Sharing your experiences and fixes will always help others.

    I just wonder about the moment a job records it is executing a next step into sysjobhistory.

    Will it only record when it receives events for it or at completion time.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply