Reputation: 36639
We are running a PowerShell script as part of our automated build in TeamCity, but it fails with the following error:
[16:31:49][Step 1/1] File F:\<path>\sript.ps1 cann
[16:31:49][Step 1/1] ot be loaded because the execution of scripts is disabled on this system. Pleas
[16:31:49][Step 1/1] e see "get-help about_signing" for more details.
I have the execution policy set to Unrestricted
on this machine:
PS C:\> Get-ExecutionPolicy
Unrestricted
and I can run this very same script manually from the PS console, just the execution from TeamCity fails. Any ideas?
EDIT: As requested:
PS C:\Users\xxx> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted
Upvotes: 0
Views: 2542
Reputation: 36639
As suggested by @Duncan, the problem was that the Machine Policy was undefined. This setting can only by changed through group policy. Within Group Policy, navigate to Computer Configuration | Administrative Templates | Windows Components | Windows PowerShell and configure the Turn On Script Execution setting and select execution policy.
More details: http://www.techrepublic.com/blog/the-enterprise-cloud/set-the-powershell-execution-policy-via-group-policy/
Upvotes: 1
Reputation: 95622
There are three scopes for execution policy: Process, Current User, Local Machine. It sounds likely that you have overridden the execution policy for your own userid but not the machine and TeamCity may be running as a different user.
As @jscott said in his comment, you should do:
Get-ExecutionPolicy -List
to get a full list of execution policies. In particular check the setting for LocalMachine.
BTW, Unrestricted
is a poor choice. RemoteSigned
is better as it will allow locally created scripts to run unsigned but will require signing for any scripts downloaded from the web.
Upvotes: 0