Unable to run powershell scripts

Oct 4, 2011 at 8:46 PM

When I change a build quaility and trigger the execution of a powershell script I get the following message back:

ERROR: File C:\Users\WoodER\AppData\Local\Temp\8f324f10-4bb3-44d7-829e-e253dc02568c\Pr
ERROR: epareForInvestigation.ps1 cannot be loaded because the execution of scripts is
ERROR: disabled on this system. Please see "get-help about_signing" for more details.
ERROR: At line:1 char:2
ERROR: + & <<<<  'C:\Users\WoodER\AppData\Local\Temp\8f324f10-4bb3-44d7-829e-e253dc025
ERROR: 68c\PrepareForInvestigation.ps1'
ERROR:     + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
ERROR:     + FullyQualifiedErrorId : RuntimeException
ERROR:

The execution policy on the machine is:

PS C:\tfsDeployer> Get-ExecutionPolicy -list

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

 

Also, I can not go to the filesystem and run teh scripo manually, because the file do not seem to persist. I changed to a simple test.ps1 script and was able to manually execute the script on the server, but get the same type of error when I execute via the service.

How can i get the scripts to execute?

 

Coordinator
Dec 9, 2011 at 4:43 AM

Hi,

The output you show for Get-Execution policy says that the policy is undefined for the CurrentUser. However, if you run PowerShell under the TFS Deployer service account and execute the same command you may see different results. Also consider restarting the TFS Deployer service if the execution policy was changed recently as it may still be cached by the service.

Finally, I never recommend setting the execution policy to Unrestricted, instead RemoteSigned is what I would normally suggest, and even AllSigned if you have the necessary certificate infrastructure in place and are particular security conscious.

Regards,

Jason

Feb 7, 2012 at 5:03 PM

I am having the same exact problem and have tried everything I found to get this to work.

I ran powershell as administrator and set the execution policy to RemoteSigned, Unrestricted and Bypass and nothing seems to work.  No matter the setting my TFS Deployer service account can't run the script because scripts are not enabled.

When I use get-executionpolicy from powershell running as asministrator I get the same results as above post.

When I use get-executionpolicy from powershell running as my TFS Deployer service account I get that LocalMachine is undefined.

What have I missed?

 

Feb 8, 2012 at 6:16 PM

I can now answer my own question...  What have I missed? When setting execution policy...

(Ensure you use the PowerShell architecture for your operating system, ie x86 vs x64).

That is an important nugget in the installation instructions.  Turns out I was setting the execution policy for the (x86) side while Powershell was running as x64.  Execution Policy is set independently for each *bit version.  Once I set the correct execution policy for 64 bit all works as planned.