Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Risks/Best practices on execution policy


Risks/Best practices on execution policy

Author
Message
Indianrock
Indianrock
SSC Eights!
SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)

Group: General Forum Members
Points: 858 Visits: 2258
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, I'm wondering what the best practices are.

Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted - No restrictions; all scripts can be run.



Gary Varga
Gary Varga
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8356 Visits: 6160
I tend to set it to RemoteSigned as opposed to Unrestricted as this is just too open for me. This does leave it open for anyone who has control of the machine, however, my thinking is that they could set the execution policy by that point anyway.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Indianrock
Indianrock
SSC Eights!
SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)

Group: General Forum Members
Points: 858 Visits: 2258
That sounds right, will have to see if group policy will change it



Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8243 Visits: 14368
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
Gary Varga
Gary Varga
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8356 Visits: 6160
opc.three is right.

The following is an extract from the help of Set-Execution-Policy:


-Scope <ExecutionPolicyScope>
Specifies the scope of the execution policy. The default is LocalMachine.

Valid values are:

-- Process: The execution policy affects only the current Windows PowerShell process.
-- CurrentUser: The execution policy affects only the current user.
-- LocalMachine: The execution policy affects all users of the computer.

To remove an execution policy from a particular scope, set the execution policy for that scope to Undefined.

Required? false
Position? 2
Default value LocalMachine
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false



So I think you are looking for Set-Execution-Policy -Scope Process

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Indianrock
Indianrock
SSC Eights!
SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)SSC Eights! (858 reputation)

Group: General Forum Members
Points: 858 Visits: 2258
Thanks to opc.three and Gary. That looks like just what I need. Powershell is shaping up to be a very useful tool. I just downloaded Idera's PowershellPlus to check it out. Our new Netapp backup tools use powershell cmdlets so this may be another area where the "scoped execution policy" will be helpful. Since our sql boxes seem to be set to Restricted, I doubt anybody but me is using powershell here (yet)



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search