While trying to run Powershell script from within VS 2017 (Package Manager Console) if you are receiving the below error-

\.nuget\packages\database.base.schema\2018.11.1.3\tools\init.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

then it is related to ExecutionPolicy setting for PowerShell script.

These  policy determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies:

  • Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted – No restrictions; all Windows PowerShell scripts can be run.

You can check the setting in your VS 2017 –> Package Manager Console by running the below command-

Get-ExecutionPolicy -List

Most probably the result will be something like this-

PM> Get-ExecutionPolicy -List

Scope                         ExecutionPolicy
———–                    —————
MachinePolicy      Undefined
UserPolicy              Undefined
Process                    Undefined
CurrentUser          Undefined
LocalMachine       Undefined

 

Solution:

You can set the ExecutionPolicy for each of the scope based on your requirement. You can set ExecutionPolicy as ‘RemoteSigned‘ for Scope Process as below-

PM> Set-ExecutionPolicy -Scope Process RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”):Y

PM> Get-ExecutionPolicy -List

Scope                               ExecutionPolicy
———–                           —————
MachinePolicy              Undefined
UserPolicy                      Undefined
Process                            RemoteSigned
CurrentUser                   Undefined
LocalMachine                Undefined

On same lines you can change ExecutionPloicy for the CurrentUser.

Note: More details can be found here –

https://docs.microsoft.com/en-gb/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1