After my laptop crashed last week I moved to Windows 7 OS and since it was a clean install (actually image) I had to install a lot of software. One bit of software I did not have to install was PowerShell. That is because it is part of the default install. Yeah!
One of the things I forgot about when first starting to work PowerShell and running scripts is the ExecutionPolicy. When trying to run a script to start SQL Server I ran into this little error.
startService.ps1 cannot be loaded because the execution of scripts is disabled on this system.
Please see “get-help about_signing” for more details.
I forgot about the default execution policy being set to restricted. This is a security feature built into Powershell. You can check your own execution policy by running this command.
# get the execution policy
#This is what PS returned:
How do we fix this you ask? That is the easy part just run this command in PowerShell.
Set-ExecutionPolicy Unrestricted # (other options are RemoteSigned and AllSigned)
Note, this will allow you to run all scripts even unsigned ones so this does pose a potential security issue to your PC or server if you set this level. To get more detailed information on what “signed” and “unsigned” scripts means type the following command.
All the information and code commands I described here can be found here on MS Tech Net