how to enable running PowerShell scripts for a different user

how to enable running PowerShell scripts for a different user

By default, Powershell scripts are not enabled for a Windows user.

Scenario: you want to run a Powershell script as a build event, from within a TFS build.  The TFS build runs on a remote machine, under a TFS build user account.

Problem: how to enable Powershell scripts, on the TFS build machine, for the build user.

______________________________
Solution 1:

This is the solution I used, although it is not ideal, as it involves setting the execution policy to unrestricted (which means that *unsigned* scripts can run locally and remotely):

1. Remote desktop into the build machine

2. run the Windows command prompt as Administrator

3. run this command:

 powershell set-executionpolicy unrestricted  

Then, to run the Powershell script, from within the build event, use this command:

 powershell.exe -executionpolicy ByPass -f MyScript.ps1  

______________________________
Solution 2: - alternative approach

Try to enable the running of  *local* Powershell scripts, for *all* users on the machine.
This is more secure than the first approach (but I could not get time from IT to help test this)

 powershell set-executionpolicy -scope localmachine remotesigned  

______________________________
More info
please see Stack Overflow.

Comments