Rename-NetVirtualAdapter.ps1

<#PSScriptInfo
.VERSION 1.0.0
.GUID a2456ad5-b0f1-4f77-a1fb-0e01dd384472
.AUTHOR Accurio
.COMPANYNAME
.COPYRIGHT 2026 Accurio
.TAGS PSEdition_Desktop PSEdition_Core Windows Network NetAdapter
.LICENSEURI https://www.apache.org/licenses/LICENSE-2.0
.PROJECTURI https://gist.github.com/Accurio/467c3a29d637fa61587088481353ba4f
.ICONURI
.EXTERNALMODULEDEPENDENCIES NetAdapter
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
 Initial release
.PRIVATEDATA
#>


# Copyright 2026 Accurio
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#Requires -Version 5.1
#Requires -Modules NetAdapter
#Requires -RunAsAdministrator

<#
.SYNOPSIS
 Rename some virtual network adapters to their descriptions
.DESCRIPTION
 This script renames some virtual network adapters, including WAN Miniport and Microsoft Wi-Fi Direct Virtual Adapters, to their descriptions.
.PARAMETER DeviceIds
 List of DeviceIDs of the adapters. By default, WAN Miniport (SWD\MSRRAS) and Microsoft Wi-Fi Direct Virtual Adapters ({5d624f94-8850-40c3-a3fa-a4fd2080baf3}) will be renamed.
.EXAMPLE
 Rename-NetVirtualAdapter
.EXAMPLE
 Rename-NetVirtualAdapter -DeviceIds @('SWD\MSRRAS')
#>


[CmdletBinding(SupportsShouldProcess = $true)]
param(
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
    [string[]]$DeviceIds = @(
        'SWD\MSRRAS'
        '{5d624f94-8850-40c3-a3fa-a4fd2080baf3}'
    )
)

$DeviceIdPrefixes = $DeviceIds.ForEach({ $_.TrimEnd('\') + '\' })

$Adapters = Get-NetAdapter -IncludeHidden | Where-Object {
    $device = $_.PnPDeviceID
    if (-not [string]::IsNullOrWhiteSpace($device)) {
        return $DeviceIdPrefixes.Where({
                $device.StartsWith($_, [StringComparison]::OrdinalIgnoreCase)
            }, 'First')
    }
} | Sort-Object -Property PnPDeviceID

foreach ($adapter in $Adapters) {
    $name = $adapter.Name
    $desc = $adapter.InterfaceDescription
    if ((-not [string]::IsNullOrWhiteSpace($desc)) -and ($name -cne $desc) `
            -and $PSCmdlet.ShouldProcess($name, "Rename to `"$desc`"")) {
        Write-Host "Rename `"$name`" to `"$desc`"" -ForegroundColor Cyan
        Rename-NetAdapter -InputObject $adapter -NewName $desc -Confirm:$false
    }
}