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

How to ping in Java

To ping in Java you can use the following snippet.

Sample Java

public static void pingUrl(String url, Integer timeOut)
{
	url = url.replace("http://", "");
	try {  
		InetAddress address = InetAddress.getByName(url);  
		System.out.println("Hostname: " + address.getHostName());  
		System.out.println("IP-Address: " + address.getHostAddress());  
		System.out.println("Reachable in " + ((double)timeOut / (double)1000) + " Seconds: " + address.isReachable(timeOut));  
	}  
	catch (UnknownHostException e) {
		System.err.println("Unable to lookup " + url + "; error: " + e);  
	}  
	catch (IOException e) {  
		System.err.println("Unable to reach " + url);  
	}  
}

Please rate this snippet

How to get the IPAddress in PHP

Sample PHP

function GetIpAddress(){   
	$ip = '';
	if(!empty($_SERVER['HTTP_CLIENT_IP']))
	{
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	}else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
	{
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	else
	{
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	return $ip;
}

Please rate this snippet