Unable to Execute PowerShell Scripts on Windows Server 2008
Have you run into a situation where you try to execute a wonderful PowerShell script that you found on the Internet and instead of executing the script you end up getting a Notepad window that opens up your script? As a workaround you open Windows PowerShell and run the script and what you get is rather bizarre. You get an error that says that scripting is disabled on your server. Hmmmm! who did that without your permission? The error says something like:
File C:\scripts\test.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\test.ps1 <<<<
Well, there are a couple of things to know about PowerShell before you start executing PowerShell scripts.
1. PowerShell is available in Windows Server 2008 as a feature. To install PowerShell, start the Server Manager. go to Features, Add features, check the Windows PowerShell box and click Install.
2. Just because you’ve installed PowerShell it doesn’t mean that you can execute scripts. Scripts can be dangerous, especially when they are allowed to run on a server. The ability to “execute” PowerShell scripts is disabled by default in Windows Server 2008. You can allow the execution by using the ExecutionPolicy option.
To view your current PowerShell Excecution Policy status, open the PowerShell console and type:
Get-ExecutionPolicy
The response you will see is “Restricted”, which is the default status. You can change the status to AllSigned, RemoteSigned, or Unrestricted.
Restricted: This default setting does not allow execution of scripts at all.
AllSigned: Allows you to only execute digitally signed scripts. This is the most secure, other than Restricted setting.
RemoteSigned: Scripts downloaded from a remote site must be digitally signed before they can be executed. This is a good setting to have for a lot of environments.
Unrestricted: All scripts can be executed but technically this isn’t what I consider a fully unrestricted setting in the sense that downloaded scripts will still offer user a prompt before executing. This should be used in rare situations and is not the recommended setting.
To change the default ExecutionPolicy, run the PowerShell as an administrator and type the appropriate command. For example, to change the Execution Policy to RemoteSigned, type:
Set-ExecutionPolicy RemoteSigned
To switch it back to default Restricted setting, type:
Set-ExecutionPolicy Unrestricted
Always verify by running Get-ExecutionPolicy to ensure that you have configured the proper settings.
Hi Alexander,
Thanks for this post! I realize it’s a bit old, but it helped me figure out what I needed to do so I could run a particular script on my server (I am a system admin in training).
Thanks again,
-Kevan-