Networknet archive Blog

PowerShell: Hyper-V switch uses the public network profile

Originally published 4 comments

While troubleshooting communication between a backup agent and server, I found this configuration on my Windows Server 2012 R2 Hyper-V host:

Public network - Hyper-V switch

The virtual network adapter for the Hyper-V switch and ManagementOS was classified as "Public network"/"Unidentified network". I wanted the domain profile because several Windows Firewall rules only allowed inbound communication from the internal domain network.

Inspect the network profile

From an elevated PowerShell prompt, I checked the current profile:

PowerShell1 line
1
Get-NetConnectionProfile

It showed NetworkCategory:Public. I tried to change it to Domain:

PowerShell1 line
1
Set-NetConnectionProfile -InterfaceAlias "vEthernet (vSwitch)" -NetworkCategory Domain
Code5 lines
1
2
3
4
5
Set-NetConnectionProfile : Unable to set NetworkCategory to 'DomainAuthenticated'.  This NetworkCategory type will be set automatically when authenticated to a domain network.
At line:1 char:1
+ Set-NetConnectionProfile -InterfaceAlias "vEthernet (vSwitch)" -NetworkCategory  ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetConnect...A858C82FCC55}"):root/StandardCi...nnectionProfile) [Set-NetConnectionProfile], CimException
+ FullyQualifiedErrorId : MI RESULT 4,Set-NetConnectionProfile

Restart Network Location Awareness

I could not change the category directly, so I opened services.msc and restarted the "Network Location Awareness" service. That resolved the problem.

The issue probably started when I created the Hyper-V virtual switch. A reboot might also have resolved it. The following command restarts the NLA service so it can find the domain controller and set the network profile:

PowerShell1 line
1
Restart-Service -Name NlaSvc -Force

4 comments

Comments from the original WordPress site, kept read-only.

  1. Wojtek

    This solution work until first reboot, after reboot network is again as Public, help!

  2. Ron

    I wrote a small script to check at boot and restart NlaSvc if nescessary:

    do
    {
                $NicCat = (Get-NetConnectionProfile -InterfaceIndex 7).NetworkCategory
                If ($NicCat -ne 'DomainAuthenticated'){
      " Network adapter not yet DomainAuthenticated, restarting NlaSvc." | Out-file $LogFile -Append
                    Restart-Service NlaSvc -Force
                    Start-Sleep -Seconds 300
                    }
    } While ($NicCat -ne 'DomainAuthenticated')
       
    " Network adapter set to DomainAuthenticated, exiting" | Out-file $LogFile -Append