Home Forums Programming Powershell Risks/Best practices on execution policy RE: Risks/Best practices on execution policy

  • FWIW I tend to use RemoteSigned on new machines. It's a decent blend that lets me do what I need to do but is not completely open.

    Indianrock (3/3/2013)


    While it would be easy to set the execution policy to unrestricted, or possibly set it to unrestricted in an agent job, do the work, then set back to restricted

    You do not need to change the execution policy for the server and in truth I think it's risky in case where someone/something else might be running PowerShell at the same time you were changing the policy. There is a switch on powershell.exe that lets us change the execution policy only for the duration of that instance of just that session.

    See the -ExecutionPolicy option:

    PowerShell.exe Command-Line Help

    When used in conjunction with -File or -Command we can let certain scripts work outside the execution policy set on the server. This is how I work around the issue I think you are facing, by running my scripts via powershell.exe in a CmdExec Agent Job Step Type and passing -ExecutionPolicy Bypass along with -File or -Command.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato