Network Connection Ids
Yesterday I was looking at changing a Network connection id (the name that shows in Network and Sharing Center when you look at the adapters). I kept getting an error – either COM or number of arguments depending if I was running locally or remotely.
I eventually realised that I must be using a connection id that already existed in the Registry. I tracked them down to
HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}
This works for Windows 7 and Windows 2008 R2. Please check for other Windows versions.
This produces a bunch of subkeys of the form
{F913D3B9-DBE4-455C-8926-10E24AB4E68A}
Each of these has a subkey Connection with a value of Name that we are interested in
function get-Registryconnectionid{
[CmdletBinding()]
param (
[string]$computer="."
)
BEGIN{}#begin
PROCESS{
Write-Verbose "Reading registry keys for IDs"
$HKLM = 2147483650
$key = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
$reg = [wmiclass]'\\.\root\default:StdRegprov'
$subkeys = $reg.EnumKey($HKLM, $key)
foreach ($name in $subkeys.snames){
if ($name -eq "Descriptions"){Continue}
$conkey = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\$name\Connection"
Write-Debug $conkey
$cvalue = "Name"
$id = $reg.GetStringValue($HKLM, $conkey, $cvalue) ## REG_SZ
$ivalue = "DefaultNameIndex"
$index = $reg.GetDwordValue($HKLM, $conkey, $ivalue) ## REG_DWORD
$connection = New-Object -TypeName PSObject -Property @{
Index = $index.uValue
Connection = $id.sValue
}
$connection
}
}#process
END{}#end
<#
.SYNOPSIS
Retrieves network connection ids
.DESCRIPTION
Retrieves network connection ids held in the registry.
This includes current and previous ids.
.PARAMETER Computer
Computer name
.EXAMPLE
get-Registryconnectionid
.EXAMPLE
get-Registryconnectionid -computer server02
#>
}
This uses the standard WMI methods to read a local or remote registry
The corresponding current values are given by
Get-WmiObject -Class Win32_NetworkAdapter | select NetConnectionId, Index
The two index values are not related