How to set the ExecutionPolicy using Powershell

To set the ExecutionPolicy using Powershell, run Powershell as Administrator.
Type in Set-ExecutionPolicy followed by the ExecutionPolicy you wish to use.

  • Restricted: Restricted is the default execution policy. PowerShell scripts are not allowed to run.
  • All Signed: All Signed means thath if they are signed by a trusted publisher.
  • Remote Signed: Remote Signed means, any PowerShell scripts that have been locally created will be allowed to run.
  • Unrestricted: As the name implies, Unrestricted removes all restrictions from the execution policy.
  • Microsoft has disabled scripting by default to prevent malicious code from being executed.

    Please rate this snippet

    NuGet: Failed to initialize the PowerShell Host

    Today i recieved the following Nuget Error while trying to install Automapper.

    Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.

    To fix that, close all Visual Studio instances and open the Powershell Console as Administrator. Enter Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted. Be aware that you need to set the execution policy on both the x86 and the x64 Powershell Console.

    A more simple solution would be to put the code below in a File with an .reg extension and execute that.

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
    "ExecutionPolicy"="Unrestricted"
    
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
    "ExecutionPolicy"="Unrestricted"
    

    Now start Visual Studio and Try Again, if the error appears again, try running Visual Studio as Administrator.

    Please rate this snippet