Debunking the Myths: Cloud HA and DR common misconceptions

Learn more about SQL Server tools



solving sql server problems for millions of dbas and developers since 2006 join MSSQLTips for free SQL Server tips


























































   Got a SQL tip?
            We want to know!

Setting the PowerShell Execution Policy

MSSQLTips author Jugal Shah By:   |   Read Comments (1)   |   Related Tips: More > PowerShell
Problem

Recently I moved PowerShell script files to a production environment and when executing it from the command prompt, I got this error: "File cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details". In this tip we cover what needs to be done to resolve this issue.

Solution

There are situations when you are executing a PowerShell script and it will give you the below error message:

File C:\scripts\regSvr.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_signing" for more details.
At line:1 char:19
+ c:\scripts\regSvr.ps1 <<<<

The reason for the above error is a security setting built into Windows PowerShell called "execution policy". Execution Policy determines how (or if) PowerShell runs scripts. By default, PowerShell's execution policy is set to Restricted; this means that scripts will not run.

You can verify the execution policy setting by using the Get-ExecutionPolicy PowerShell command as shown below.

get-executionpolicy

PowerShell Console

You can change the PowerShell script execution behavior using "Set-ExecutionPolicy". The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts will be allowed to run on your computer.

Windows PowerShell has four different execution policies:

  • 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.

To get more information on Set-ExecutionPolicy, type "Get-Help Set-ExecutionPolicy" as shown below.

get-help set-executionpolicy

getHelpSetExecutionPolicy PowerShell

To execute the Set-ExecutionPolicy command, you must have administrator permission and for Windows Vista / Windows Server 2008 and later versions you have to open the PowerShell command prompt with Run As Administrator. Otherwise you will get the below error.

set-executionpolicy unrestricted

PowerShell Access Denied Errors

You can set the execution policy as per your requirement as shown below.

set-executionpolicy unrestricted
get-executionpolicy

--or
set-executionpolicy remotesigned
get-executionpolicy

PowerShell Set-Execution Policy Example
Next Steps
  • Check your different PowerShell environments for the current execution policy that is in place.
  • Set the execution policy as per your need for each system
  • Review these other PowerShell tips


Last Update: 5/22/2012


About the author
MSSQLTips author Jugal Shah
Jugal Shah has 8+ years of extensive SQL Server experience and has worked on SQL Server 2000, 2005, 2008 and 2008 R2.

View all my tips
Related Resources


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Comments and Feedback:
Monday, March 04, 2013 - 7:05:22 PM - Dariusz Fabicki Read The Tip

Best :)



Post a Comment or Question

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email Notify for updates



Comments
Get free SQL tips:

*Enter Code refresh code


 
Sponsor Information







Copyright (c) 2006-2014 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | free t-shirt | user groups | community | events | first timer?
Some names and products listed are the registered trademarks of their respective owners.