views:

67

answers:

3

So I wanted to get started with writing a powershell script. I wanted to start small and simply write a script that substiutes a local file folder as a drive. Pretty simple. I've done it before using the old DOS command tools.

So the script I wanted to write is:

subst d: G:\CER

Ok, so I try to execute the script in the Powershell ISE by pressing the 'Play' button (i.e. F5)

So what do I get?

File G:\CER\Make_Stage.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:0 char:0

How stupid is this, that out of the box execution of powershell scripts are disabled! i.e. By default! Simply incredible that by default this new tool simply does not work. Powershell has to be the stupidest scripting shell out there.

So apparently I have to register something somewhere (hopefully not with MS). If anyone has an answer as to how to fix this, I'd appreciate it.

+2  A: 

To fix this, execute:

set-executionpolicy remotesigned

In an elevated PowerShell prompt.

driis
+7  A: 

To enable scripting, open a powershell prompt as Administrator and run:

Set-ExecutionPolicy RemoteSigned

Here's a blog post from Lee that talks about PowerShell's security principles (http://www.leeholmes.com/blog/2005/08/16/demonstration-of-monads-security-features/).

Keep in mind that most computer will never run a PowerShell script.

Jay Bazuzi
Thanks for the answer. That's precisely what I needed.
C Johnson
Although, actually, "most computers will never" isn't true. Microsoft is using PowerShell in their "Fix It" stuff, but you can override ExecutionPolicy on the PowerShell.exe command-line to get around it without changing the setting.
Jaykul
Also: if you're not the administrator, you can still: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Jaykul
@Jaykul: is this what "Fix it" doing?
zespri
@zespri: I haven't specifically check how they're doing it, but they're either calling PowerShell with a -ExecutionPolicy parameter, or they have their own custom host (unlikely)...
Jaykul
A: 

Found it:

From the help docs (deeep in the help docs)

LONG DESCRIPTION The Restricted execution policy does not permit any scripts to run.

A long article ensues on how to set an execution policy. I'm not impressed so far with PS.

C Johnson