Today I was working on building PowerShell script to establish SQL Server Database Mirroring. To start with PowerShell, I tried to execute my first built of PowerShell Script on SQLPS, I received the following error.
File C:\Temp\Mirroring\Script\DBMirrroringSetup.ps1 cannot be loaded. The file C:\Temp\Mirroring\Script\DBMirrroringSetup.ps1 is not digitally signed. The script will not execute on the system. Please see “get-help about_signing” for more details..
At line:1 char:47+ C:\Temp\Mirroring\Script\DBMirrroringSetup.ps1 <<<< + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException
You may also get Error “The execution of scripts is disabled on this system”
As per the error message, the script is not trusted to be run on your system. This is because, my current security policy doesn’t allow to run any PowerShell Script, which is not Digitally signed.
FIX / Resolution
I have seen this issue in past where I get error “execution of scripts is disabled on this system”, to fix this, I modified security settings and asked PowerShell environment to run any PowerShell Script by setting ““ExecutionPolicy” as Unrestricted, using the following command in PowerShell window “Set-ExecutionPolicy Unrestricted”
Note : Make sure, the command prompt / PowerShell window is opened with elevated privileges, I mean to say, run as Administrator Mode.
After that, when I ran my PowerShell script, that worked without any issues.
