I have one PowerShell script which sends emails. I want to execute that script automatically, every 1 minute. How can I do it, using task scheduler?
Currently I have
You can use the Unblock-File cmdlet to unblock the execution of this specific script. This prevents you doing any permanent policy changes which you may not want due to security concerns.
Unblock-File path_to_your_script
Source: Unblock-File
In my case, my script has parameters, so I set:
Arguments: -Command "& C:\scripts\myscript.ps1 myParam1 myParam2"
Instead of only using the path to your script in the task scheduler, you should start PowerShell with your script in the task scheduler, e.g.
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -File "C:\Path\To\Your\PS1File.ps1"
See powershell /?
for an explanation of those switches.
If you still get problems you should read this question.
None of posted solutions worked for me. Workaround, which worked:
create a run.bat
and put inside
powershell.exe -file "C:\...\script.ps1"
then set Action to Program/Script: "C:\...\run.bat"
I also could not launch scripts, after heavy searching nothing helped. No -ExecutionPolicy, no commands, no files and no difference between "" and ''.
I simply put the command I ran in powershell in the argument tab: ./scripts.ps1 parameter1 11 parameter2 xx
and so on. Now the scheduler works.
Program: Powershell.exe
Start in: C:/location/of/script/
Create the scheduled task and set the action to:
Program/Script: Powershell.exe
Arguments: -File "C:\Users\MyUser\Documents\ThisisMyFile.ps1"