Microsoft Windows Powershell is becoming more and more popular now. It’s quickly going to replace MS-DOS (.cmd/.bat) and VBScript (.vbs) scripts as THE way to do things. If you need to test your scripts locally however, you will not be able to do so with a default PowerShell installation. Here’s why …

The following information applies to both Windows Vista and Windows Server 2008.

PowerShell has 4 different executation policies. Restricted (default) - No scripts are executed, signed or not. AllSigned - scripts that are trusted are executed, meaning they must be properly signed. Run the following command for full details on signing.

Get-Help About_Signing

The next execution policy is RemoteSigned - all local scripts will be executed but scripts downloaded through Internet Explorer or Microsoft Outlook etc must be signed. The final execution policy is Unrestricted - all scripts will be executed although downloaded scripts will prompt to make sure you want to run them before they actually DO run.

For local testing purposes, i.e. for scripts you have written yourself, the best way to make sure they’re executed properly while still maintaining some level of security is to set the execution policy to RemoteSigned. This is, of course, unless you have purchased a digital certificate which you intend to use with your PowerShell scripts. In this case it’s probably better to set the execution policy to AllSigned. To see the current execution policy on your system, run the following command inside a PowerShell command window.

Get-ExecutionPolicy

If we assume for the moment that your installation is still running as default, this will produce the following result.

PowerShell - Get-ExecutionPolicy

As you can see, the execution policy is currently set as Restricted. To change the execution policy so you can run local scripts that aren’t signed but can’t run remote scripts that aren’t signed, run the following command.

Set-ExecutionPolicy RemoteSigned

The following screenshot shows the result of changing the security policy then checking that it’s taken effect (ignore the fact that the image has been cut off at the right side, just make sure you’re entering the command as highlighted above!).

PowerShell - Set-ExecutionPolicy

As you can see, there isn’t a whole lot of output from these commands (when run that way). It does show, however, that the execution policy has been set to RemoteSigned.

The main point here is that you’ll need to do this before you can run PowerShell scripts locally. It’s pretty handy to know!