PowerShell NetConnection & NetworkConnectivityStatus
How does Windows decide between Internet, No Internet and a captive portal sign-in? NCSI probes decide it. The NetConnection module shows and sets the connection profile (network category), and NetworkConnectivityStatus handles DirectAccess status and corporate NCSI probe policy.
227.1 What it does, where it runs
- Both modules are built into Windows 10/11 and Windows Server; PowerShell 5.1 and 7.
- NetConnection: profile of every network connection + its network category.
- NetworkConnectivityStatus: DirectAccess status + NCSI policy configuration.
- Together they have 6 cmdlets; Set and Reset need an Administrator PowerShell.
- On the office PC even Get shows the office network name, so only Get-Command and Get-Help ran.
Get-Command -Module NetConnection, NetworkConnectivityStatus | Measure-ObjectGet-Help Get-NetConnectionProfile$ Get-Command -Module NetConnection,NetworkConnectivityStatus | Measure-ObjectCount : 6$ Get-Help Get-NetConnectionProfile (trimmed)Synopsis : Get-NetConnectionProfile [-Name <string[]>] [-InterfaceAlias <string[]>] [-InterfaceIndex <uint32[]>] [-NetworkCategory <NetworkCategory[]>] [-DomainAuthenticationKind <DomainAuthenticationKind[]>] [-IPv4Connectivity <IPv4Connectivity[]>] [-IPv6Connectivity <IPv6Connectivity[]>] [-CimSession <CimSession[]>] [-ThrottleLimit <int>] [-AsJob] [<CommonParameters>]ModuleName : NetConnectionThe local syntax shows -DomainAuthenticationKind, which is not on the docs page: always check Get-Help on your own Windows.
227.2 How it works: NCSI probes
- Step 1
1.PC joins a network; NLA + NCSI start an active probe
- Step 2
2.DNS probe via router 192.168.1.1 and ISP: dns.msftncsi.com A?
- Step 3
3.Answer 131.107.255.255: DNS probe OK
- Step 4
4.HTTP probe: GET /connecttest.txt from www.msftconnecttest.com
- Step 5
5.200 OK, body: Microsoft Connect Test
- Step 6
6.IPv4Connectivity : Internet, taskbar shows the internet icon
- Step 1
1.Laptop on hotel Wi-Fi sends GET /connecttest.txt
- Step 2
2.Hotel router does not forward it: sign in first
- Step 3
3.Router replies with a 302 / its own login page
- Step 4
4.Body is not Microsoft Connect Test: IPv4Connectivity : LocalNetwork
- Step 5
5.Windows notifies you to open the sign-in page
- Step 6
6.After sign-in the next probe passes: Internet
- Besides active probes, passive probing updates the status from the hop count of incoming packets.
227.3 Connectivity levels and network category
| Value | Type | Meaning |
|---|---|---|
| Disconnected | Connectivity | No link at all |
| NoTraffic | Connectivity | Link up, but no traffic |
| Subnet | Connectivity | Only your own subnet is reachable |
| LocalNetwork | Connectivity | Gateway reachable, internet not (or captive portal) |
| Internet | Connectivity | NCSI probes pass |
| Public | Category | Strictest firewall profile (cafe, airport) |
| Private | Category | Home / trusted network |
| DomainAuthenticated | Category | Authenticated to a DC; set by Windows only |
227.4 Get-NetConnectionProfile (7) + Get-DAConnectionStatus (1)
- Filters: -Name (network name), -InterfaceAlias, -InterfaceIndex, -NetworkCategory, -IPv4Connectivity / -IPv6Connectivity.
- Common parameters: -AsJob, -CimSession (remote), -ThrottleLimit; Set cmdlets also take -Confirm and -WhatIf.
- Get-DAConnectionStatus returns DirectAccess status + sub status; no object = not configured for DirectAccess.
Get-NetConnectionProfile ` -InterfaceAlias "Ethernet1" | Set-NetConnectionProfile ` -NetworkCategory PublicGet-DAConnectionStatus227.5 Set-NetConnectionProfile (9)
- Changes the network category of a profile: Public or Private.
- Select by -Name, -InterfaceAlias, -InterfaceIndex or pipe with -InputObject; -PassThru returns the changed profile (otherwise no output).
- DomainAuthenticated cannot be set: Windows sets it when a DC authenticates the network.
- The category decides the firewall profile and network discovery, not internet quality.
Set-NetConnectionProfile ` -InterfaceAlias Ethernet1 ` -NetworkCategory "Public"227.6 NCSI policy cmdlets (corporate probes)
- Get-NCSIPolicyConfiguration (3): reads NCSI config from -PolicyStore (ActiveStore or Domain\GPOName) or a -GPOSession (not both).
- Set-NCSIPolicyConfiguration (12): sets corporate probes in a GPO.
- CorporateDNSProbeHostName + CorporateDNSProbeHostAddress = DNS probe: name resolves to the expected IP = corporate connectivity.
- DomainLocationDeterminationURL: HTTPS URL; reachable = PC is inside the corporate network.
- Reset-NCSIPolicyConfiguration (10): back to not configured; same-named switches reset single fields.
Get-NCSIPolicyConfiguration ` -PolicyStore "contoso\davidchew"Set-NCSIPolicyConfiguration ` -PolicyStore "contoso\davidchew" ` -CorporateWebsiteProbe "http://contoso.com"Reset-NCSIPolicyConfiguration ` -PolicyStore "contoso\davidchew"PS C:\> Get-NCSIPolicyConfiguration -PolicyStore "contoso\davidchew"Description : NCSI ConfigurationCorporateDNSProbeHostAddress : 2001:4898:1337:1337:1337::1337CorporateDNSProbeHostName : corp.contoso.comCorporateSitePrefixList : 2001:4898::/32,2006:1601::/32,2a01:0110::/31CorporateWebsiteProbeURL : http://web.contoso.comDomainLocationDeterminationURL : https://io.contoso.com227.7 Linux equivalent: NCSI with dig + curl
- Docker lab only, never contacts the real msftconnecttest.com: dnsmasq answers lab names, a small HTTP server serves connecttest.txt.
- DNS probe: dig must return 192.168.247.99; HTTP probe: curl body must be exactly Microsoft Connect Test.
#!/bin/sh# NCSI-style check, lab names onlyip=$(dig +short +time=2 +tries=1 dns.ncsi.lab)[ "$ip" = 192.168.247.99 ] && d=OK || d=FAILu=http://www.ncsi.lab/connecttest.txtbody=$(curl -s -m 3 "$u")echo "DNS probe : $d ($ip)"echo "HTTP body : ${body:-<no response>}"if [ "$body" = "Microsoft Connect Test" ]then r=Internetelif [ -n "$body" ]then r="LocalNetwork (captive portal)"else r="LocalNetwork (probe failed)"fiecho "Result : $r"[client] $ dig +noall +answer dns.ncsi.labdns.ncsi.lab. 0 IN A 192.168.247.99[client] $ curl -s -i http://www.ncsi.lab/connecttest.txtHTTP/1.1 200 OKContent-type: text/plainContent-Length: 22 Microsoft Connect Test[client] $ sh /root/ncsi-check.shDNS probe : OK (192.168.247.99)HTTP body : Microsoft Connect TestResult : Internet $ docker stop n227-web[client] $ curl -s -m 3 http://www.ncsi.lab/connecttest.txt; echo "curl exit $?"curl exit 28[client] $ sh /root/ncsi-check.shDNS probe : OK (192.168.247.99)HTTP body : <no response>Result : LocalNetwork (probe failed) [probe] $ printf '<html><h1>Hotel Wi-Fi</h1>Please sign in</html>' > /www/connecttest.txt[client] $ sh /root/ncsi-check.shDNS probe : OK (192.168.247.99)HTTP body : <html><h1>Hotel Wi-Fi</h1>Please sign in</html>Result : LocalNetwork (captive portal)- Probe server stopped: DNS still OK, curl times out (exit 28), result LocalNetwork, like 'No Internet' on Windows.
- Login page served with 200 OK: content mismatch = captive portal, exactly what NCSI looks for.
227.8 Common mistakes
- Setting a network to Private to 'fix the internet': the category only changes the firewall profile and discovery.
- Setting cafe/airport Wi-Fi to Private; keep it Public there.
- Trying to set DomainAuthenticated with Set-NetConnectionProfile; only Windows sets it.
- Troubleshooting LocalNetwork on public Wi-Fi without first opening a page in the browser (captive portal).
227.9 Interview tips
- No Internet logic: NCSI active probes, DNS for dns.msftncsi.com and HTTP for /connecttest.txt.
- Body Microsoft Connect Test = Internet; failure = LocalNetwork; different content = captive portal.
- Passive probing uses hop counts; corporate probes are set with Set-NCSIPolicyConfiguration.
- Network category = firewall profile (Public strictest); DomainAuthenticated is set by Windows.
- Cafe Wi-Fi with full signal but LocalNetwork: open a page in the browser to hit the sign-in portal.