Friday, January 3, 2014

Change unidentified networks to private

Working with Hyper-V in windows 8 you might need to change the private network location to private in order to access the host's web server from a client virtual machine (e.g. testing a site in older browsers). By default, the private network doesn't contain any domain controller or dns server and you might have static ips on your vms and the host. This means that by default the connection's location is public as the network is unidentified. To change the location of your unidentified networks to private, I found a powershell script.

Just for archiving purposes the script is the following:
# Copied from http://blogs.msdn.com/b/dimeby8/archive/2009/06/10/change-unidentified-network-from-public-to-work-in-windows-7.aspx
#
# Don't forget to run "set-executionpolicy remotesigned" to enable ps1 execution.
# Run this as admin
#
# Name: ChangeCategory.ps1
# Copyright: Microsoft 2009
# Revision: 1.0
#
# This script can be used to change the network category of
# an 'Unidentified' network to Private to allow common network
# activity. This script should only be run when connected to
# a network that is trusted since it will also affect the
# firewall profile used.
# This script is provided as-is and Microsoft does not assume any
# liability. This script may be redistributed as long as the file
# contains these terms of use unmodified.
#
# Usage:
# Start an elevated Powershell command window and execute
# ChangeCategory.ps1
#
$NLMType = [Type]::GetTypeFromCLSID('DCB00C01-570F-4A9B-8D69-199FDBA5723B')
$INetworkListManager = [Activator]::CreateInstance($NLMType)
$NLM_ENUM_NETWORK_CONNECTED = 1
$NLM_NETWORK_CATEGORY_PUBLIC = 0x00
$NLM_NETWORK_CATEGORY_PRIVATE = 0x01
$UNIDENTIFIED = "Unidentified network"
$INetworks = $INetworkListManager.GetNetworks($NLM_ENUM_NETWORK_CONNECTED)
foreach ($INetwork in $INetworks)
{
$Name = $INetwork.GetName()
$Category = $INetwork.GetCategory()
if ($INetwork.IsConnected -and ($Category -eq $NLM_NETWORK_CATEGORY_PUBLIC) -and ($Name -eq $UNIDENTIFIED))
{
$INetwork.SetCategory($NLM_NETWORK_CATEGORY_PRIVATE)
}
}

Be warned, all unidentified networks turn into private location, until your next reboot. After that, you will have to run the script again.
There is also a local security policy hack which is permanent but I strongly advice against it, as it is permanent.
 

No comments: