0

I have several scheduled tasks stored in Windows Server 2016. But none of them are executed at the appointed time. If I run them manually, they will run properly. I have also created some tasks in the SQL server that run manually but do not run according to schedule. What is the problem?

enter image description here

hmahdavi
  • 341
  • 1
  • 7
  • 17

2 Answers2

0

That is happening because of Window's Execution policy, Which does not allow an unsigned powershell script to be run by another program by default. You need to change this policy for your tasks to work.

  1. Open an elevated Powershell prompt.
  2. Type Set-ExecutionPolicy Unrestricted to set the policy to Unrestricted.
  3. Type Get-ExecutionPolicy to verify the current settings for the execution policy.

Please note that changing this setting can be a security threat as malicious scripts can also be run by other programs. Instead you can try to write a Batch script spinoff of the same script(if it's possible), and then use that instead of this. Windows exeution policy don't block Batch scripts.

Saaransh Garg
  • 2,596
  • 14
  • 27
  • I checked this on other servers. And I realized that there is no difference between them in this case. There must be another reason for the problem – hmahdavi Feb 01 '22 at 07:06
0

I know this is old, but you likely need to digitally sign any PowerShell scripts. The advice to set the execution policy to unrestricted is terrible advice, and it's likely your security team would have prevented that from being changed anyway.

get-help Set-AuthenticodeSignature

e.g: Set-AuthenticodeSignature -FilePath .\Path_to_script.ps1 -Certificate (Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert)

(this assumes you have a code signing cert in your personal certificate store)