Share via

Execution of Powershell script fails on SQL Agent

Kai Herrmann 21 Reputation points
2022-09-06T19:17:53.303+00:00

Hi,

I have developed a powershell script that calls an executable with a time limit of 15 minutes

To implement this I downloaded the package for the Start_threadjob from the powershell library. The script runs as expected when executing the script on the server from powershell or as compiled exe file

Code:

   # execute program as thread job with a maximum run time of 15 minutes.   
     
   $ESDjob = Start-ThreadJob { & $using:prgPath @using:prgArgs}  

But when I run this as a step of a SQL agent job, the error below is thrown:

The term 'Start-ThreadJob' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I have other PS modules that I downloaded that can be executed as SQL agent. What could cause this issue?

Windows for business | Windows Server | User experience | PowerShell
SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Olaf Helper 47,621 Reputation points
2022-09-07T05:13:46.12+00:00

The term 'Start-ThreadJob' is not recognized as the name of a cmdlet,

It's because it's not a default CmdLet available in a SQL Server-Agent job; you have to import the CmdLet in your script first.

But why, the job should already run as it's own thread, don't make much sense to use additional threading?

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. PandaPan-MSFT 1,931 Reputation points
    2022-09-07T03:11:49.157+00:00

    Hi @Kai Herrmann ,
    Maybe you can try to update your version to 1.11.0. I find one article that may give you some help.https://github.com/jdhitsolutions/PSCalendar/issues/19

    Best regards
    Jong


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment"

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.