Running PS script as task action

This topic contains 3 replies, has 2 voices, and was last updated by  Bojan Zivkovic 3 years, 5 months ago.

  • Author
    Posts
  • #14634

    Bojan Zivkovic
    Participant

    Hi, IT department of company from which my company bought core banking software defined one task in task scheduler on Windows Server 2008 R2 which was triggered by certain event log. As an action they defined sending an email to our IT department. As soon as it is received, one of as (system engineers) has to manually restart one service on that server (in doing so also one more service that depends on the first one will be restarted). By default execution policy on server is restricted.

    If I use simple script with just one line restart-service -name servicename -force and add it as an action for task do I need to change execution policy to remotesigned or it can be left as default. When I used PS script and deployed it using GPO I did not need to change execution policy on computers in domain.

    Thanks in advance!

  • #14636

    deiandrei
    Participant

    Yes. You need an additional line which starts the dependent service.
    A little explanation on this:
    A service "B" which depends on service "A" means that service B can't run when A is stopped. So, stopping service A will also kill service B.
    But starting service A does not mean that B is also being started. So you need to start both of them separately.

  • #14639

    Bojan Zivkovic
    Participant

    What about execution policy? Does it have to be changed to remotesigned if task runs the script?

  • #14635

    Bojan Zivkovic
    Participant

    I tested by running restart-service -name servicename -force in PS console and it restarted the first service but dependent service was stopped and stayed stopped. It seems that after restart-service -name servicename -force one more line in script is needed start-service -name dependentservicename?

You must be logged in to reply to this topic.