Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



Windows PowerShell Set-ExecutionPolicy

Windows PowerShell Set-ExecutionPolicy

It comes as a shock to realize that by default, and by design, PowerShell code just won't execute because of security concerns.  Fortunately you can change this behavior easily with Set-ExecutionPolicy.PowerShell Set-ExecutionPolicy

Set-ExecutionPolicy Topics

 ♣

PowerShell Pre-requisites and Checklist

In the case of Windows 7 and Server 2008, you don't need to download any extra files, just 'Add Feature' Windows PowerShell.  However, for older operating systems, installing can be confusing because there are different versions of PowerShell for XP, Windows Server 2003 and Vista.  For such legacy systems only, you need to download PowerShell from Microsoft's site.

Once you have installed PowerShell 2.0, I recommend choosing the ISE (Integrated Scripting Engine) version, it will save you buying a text editor.

A Quick Look at Get-ExecutionPolicy

I like experiments.  Get-Execution allows us to take a snapshot before we make any changes with 'Set'.  My other reason for introducing 'Get' is to help with troubleshooting why scripts are or are not working.

# PowerShell Check Scripts
Clear-Host
Get-ExecutionPolicy

PowerShell Execution Policy Values

Restricted (Default)
RemoteSigned (Guy's favourite. Local scripts OK)
Unrestricted (Gung-ho setting, useful for testing)
AllSigned (Secure but a pain to setup)
Bypass (Never used)
Undefined (Tricky setting)

Set-ExecutionPolicy

Not only is this a job that needs doing so that all your other PowerShell scripts work, but also changing the script execution behaviour gives you valuable experience with the 'Set' verb.

# PowerShell Set Script Behaviour
Clear-Host
Set-ExecutionPolicy RemoteSigned

Note : Because all that you get is the message below, you may wish to append this line:
Get-ExecutionPolicy

Set-ExecutionPolicy

Guy Recommends: Permissions Analyzer - Free Active Directory ToolFree Permissions Monitor

I like the Permissions Monitor because it enables me to see quickly WHO has permissions to do WHAT.  When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!

Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource.

Download Permissions Analyser - Free Active Directory Tool

Researching Set-ExecutionPolicy

These simple mini PowerShell tutorials will help you to use Get and Set-Executionpolicy to find out where your scripts fail to run.

Help With Set-ExecutionPolicy Parameters

# PowerShell Set-ExecutionPolicy Parameters
Clear-Host
Get-Help Set-ExecutionPolicy

Checking the help file may reveal useful parameters, for instance -list may help with troubleshooting, see more below.

Troubleshooting Set-ExecutionPolicy

While you do all of the above and configure Set-ExecutionPolicy scripts may still not run because of Group Policy restrictions.  Here are the factors to consider:

 Computer Group Policy > User Group Policy > Process (session) execution policy > User execution policy > Computer execution policy.

# PowerShell Set-ExecutionPolicy List
Clear-Host
Get-Help Set-ExecutionPolicy -list

Typical Results From Listing ExecutionPolicies

Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine RemoteSigned

Summary of Get-ExecutionPolicy

Having to adjust Get-ExecutionPolicy is the price we pay for security, administrator must be allowed to turn off PowerShell code to stop hackers or their viruses gaining control.  Set-ExecutionPolicy tackles the specific problem that your PowerShell script will not run.  Fortunately if you don't like this behavior you can change it easily with Set-ExecutionPolicy.

If you like this page then please share it with your friends

 


See more Windows PowerShell tutorials

PShell Home  • Introduction   • Dreams   • 3 Key Commands   • PowerShell v 3.0

Process example   • Backtick   • Get-Command   • PowerShell ISE   • Cmdlet scripts

Windows PowerShell    • Set-ExecutionPolicy   • PowerShell examples   • Get-Member

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.