Link to home
Start Free TrialLog in
Avatar of Jan Nielsen
Jan Nielsen

asked on

Error when running PowerShell script in Task Scheduler

Hi

When I run a Power Shell script in a Task Scheduler I get an error
"The PS1 file is dot digitally signed"

I have tried to use the command "-ExecutionPolicy Bypass" before the path to the PS1 file, in the action--> add arguments section.
Have also tried "-Scope Process -ExecutionPolicy Bypass" but still not working

does anybody have an idea to solve this problem?

/Jan Nielsen
 
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

A GPO may set the execution policy. This blocks the execution.
Check the value of HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ExecutionPolicy or run
 Get-ExecutionPolicy -List

Open in new window


If its not set by a GPO, try

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine

Open in new window

Try putting the execution policy in the initial call for the powershell.exe in the task scheduler.
so in the path in task scheduler for your script for example use.
powershell.exe -ExecutionPolicy Bypass -File \\path\to\script.ps1

Open in new window

Avatar of Jan Nielsen
Jan Nielsen

ASKER

Hi Michael


I have tried it in PS an there it works one time, but if I try using it in the scheduler it does not work, any other ideas?


Open in new window

Hi Robert

I
I have tried your suggestion too, but with the same result, it does not work

Open in new window




Whats the output of  

Get-ExecutionPolicy -List

When run from an elevated PowerShell.
Is the PowerShell script located on a remote share?
If its local it should just run without being signed.

Which user is trying to start the scheduled task? Local System?
Hi Michael

I have tried both local and remote share, but with same result, also I have tried with Local System, Local Administrator, Domanin administrator, but with same result
And you always get an error regarding an unsigned PS script? Thats weird.
ASKER CERTIFIED SOLUTION
Avatar of Robert
Robert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial