Powershell script does not get executed by Task Scheduler

That is happening because of Window's Execution policy, Which does not allow an unsigned script to be run by default. You need to change this policy for your script 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 is 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, and then use that instead of this. Windows exeution policy don't block Batch script.