Powershell Execution Policy Issue


I’m getting the following error when trying to deploy a package with powershell pre/post deploy scripts:

2012-06-20 14:34:18 DEBUG  Looking for PowerShell scripts named PreDeploy.ps1
2012-06-20 14:34:18 INFO   Calling PowerShell script: 'C:\Octopus\Tentacle\Applications\SIT\ACENextService\1.0.2_1\PreDeploy.ps1'
2012-06-20 14:34:26 DEBUG  Script 'C:\Octopus\Tentacle\Applications\SIT\ACENextService\1.0.2_1\PreDeploy.ps1' completed.
2012-06-20 14:34:26 DEBUG  Script output:*
2012-06-20 14:34:26 DEBUG  ERROR: Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope.  Due to the override, your shell will retain its current effective execution policy of "RemoteSigned". Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information, please see "Get-Help Set-ExecutionPolicy."
ERROR: At line:1 char:20
ERROR: + Set-ExecutionPolicy <<<<  Bypass -Scope Process
ERROR:     + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
ERROR:     + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
2012-06-20 14:34:26 DEBUG  Return code of PowerShell script: -12
2012-06-20 14:34:26 ERROR  Error while executing job: PowerShell script 'C:\Octopus\Tentacle\Applications\SIT\ACENextService\1.0.2_1\PreDeploy.ps1' returned non-zero exit code: -12. Deployment terminated.
Octopus.Tentacle.Deployment.Integration.PowerShell.ScriptFailureException: PowerShell script  'C:\Octopus\Tentacle\Applications\SIT\ACENextService\1.0.2_1\PreDeploy.ps1' returned non-zero exit code: -12. Deployment     terminated.
   at Octopus.Tentacle.Deployment.Conventions.PowerShellConvention.AfterDeployment(ConventionContext context) in         c:\BuildAgent\work\7bf5272a44079f5\source\Octopus.Tentacle\Deployment\Conventions\PowerShellConvention.cs:line 41
   at Octopus.Tentacle.Deployment.DeploymentController.Execute(PackageMetadata package, VariableDictionary variables) in c:\BuildAgent\work\7bf5272a44079f5\source\Octopus.Tentacle\Deployment\DeploymentController.cs:line 64
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at Octopus.Tentacle.Services.Jobs.JobQueue.RunDeploymentsOnBackgroundThread(Object ignored) in  c:\BuildAgent\work\7bf5272a44079f5\source\Octopus.Tentacle\Services\Jobs\JobQueue.cs:line 85

I’ve been looking into this and I believe it has something to do with Octopus automatically setting the execution policy to bypass. My Execution policy is:

PS H:> get-executionpolicy -List

                              Scope                         ExecutionPolicy
                              -----                         ---------------
                      MachinePolicy                            RemoteSigned
                         UserPolicy                               Undefined
                            Process                               Undefined
                        CurrentUser                               Undefined
                       LocalMachine                               Undefined

I’ve tried to change the Machine policy, but it seems like our company policy will not allow us to change this. Is there anything in Octopus I can change to get around this issue?


Hi Alex,

Thanks for the report. You’re correct that Octopus tries to change the execution policy. I’ll release a patch tonight that allows Octopus to ignore an error in changing the execution policy, in which case it will continue to run in RemoteSigned.


Hi Paul,

Thanks for the fast turnaround on this. I just applied the patch and it’s all working.