IT tutorials
 
Applications Server
 

Sharepoint 2010 : Windows PowerShell Scripts (part 1) - Setting the Execution Policy

11/18/2014 8:17:02 PM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
Scripts in Windows PowerShell are basically sequences of commands stored in a text file. A script in Windows PowerShell must have the file name extension .ps1 and can contain functions such as the ones described in the previous section. Like functions, scripts in Windows PowerShell can use parameters to accept input.

Windows PowerShell was designed with security in mind. One security feature is that files with the extension .ps1 are associated with Notepad, rather than Windows PowerShell. This prevents users from accidentally clicking a script and executing it unintentionally.

Another security feature is the execution policy, which controls how scripts can be executed. Before we get started with writing scripts, let’s take a quick tour of the execution policies in Windows PowerShell.

Setting the Execution Policy

Windows PowerShell supports execution policies that let you define criteria for allowing scripts to execute. The execution policies for the local computer and current users are stored in the registry. The following are the Windows PowerShell execution policies:

  • Restricted This is the default policy. It permits commands and functions to be run in the Windows PowerShell console, but will not run scripts.

  • AllSigned This policy allows execution of scripts, but requires them to be digitally signed by a trusted publisher, including scripts written on your local computer.

  • RemoteSigned This policy allows scripts written on the local computer to be executed, but does not allow execution of scripts downloaded or received by e-mail, unless they are digitally signed.

  • Unrestricted With this policy, Windows PowerShell runs all scripts, but displays a warning for scripts originating from the Internet.

Note

Windows PowerShell (or any component of the operating system) can tell whether or not a script or file originating from the Internet is trusted by the zone information contained in a specified alternative data stream of the file. All it takes to turn an Internet file into a local file is opening the file’s properties and clicking the Unblock button (this applies to Windows XP SP2 and Internet Explorer 7 and later).


You can use the Get-ExecutionPolicy cmdlet to retrieve the current execution policy on the local computer.

PS > Get-ExecutionPolicy
Restricted

In this example, the policy is set to Restricted, which is the default.

To set a Windows PowerShell execution policy, you need elevated privileges. To run Windows PowerShell with elevated privileges, right-click the Windows PowerShell icon and click Run as Administrator.

Note

Since there is no User Access Control (UAC) in Windows XP or Windows Server 2003, the Run as Administrator option does not apply to those operating systems.


You can now use the Set-ExecutionPolicy cmdlet to change the execution policy. Here’s an example of changing the policy to RemoteSigned:

PS > Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust.
Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic.
Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
 
Others
 
- Sharepoint 2010 : Windows PowerShell Functions
- Sharepoint 2013 : Security and Policy - SharePoint Users
- Sharepoint 2013 : Security and Policy - Permissions and Permission Levels (part 2) - Creating Custom Permission Levels
- Sharepoint 2013 : Security and Policy - Permissions and Permission Levels (part 1)
- Sharepoint 2013 : Security and Policy - Security Administration
- Installing Exchange Server 2010 : Command-Line Setup (part 2) - Command-Line Server Recovery Options , Command-Line Delegated Server Installation , Installing Language Packs
- Installing Exchange Server 2010 : Command-Line Setup (part 1) - Command-Line Installation Options
- Installing Exchange Server 2010 : Graphical User Interface Setup
- Installing Exchange Server 2010 : Preparing for Exchange 2010 Ahead of Time (part 2) - Preparing the Active Directory Forest,Preparing Additional Domains
- Installing Exchange Server 2010 : Preparing for Exchange 2010 Ahead of Time (part 1) - Existing Exchange Organizations , Preparing the Schema
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS