You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过PowerShell根据VPN地址查找并修改VPN连接名称?

修改VPN连接名称的PowerShell实现

问题说明

Set-VpnConnection 没有直接重命名VPN连接的参数,你之前的写法会把第二个字符串误解析为 -ServerAddress 的参数值,导致修改的是VPN地址而非名称。

正确解决方案

步骤1:获取目标VPN连接

先筛选出符合ServerAddress条件的VPN连接,保存到变量中:

$targetVpn = Get-VpnConnection | Where-Object { $_.ServerAddress -like '*vash*' }

步骤2:重命名VPN连接

使用 Rename-NetConnection(专门用于修改网络连接名称的cmdlet,VPN属于网络连接范畴)完成重命名,同时增加判断避免空对象报错:

if ($targetVpn) {
    # 替换为你想要的新名称
    $newVpnName = "新VPN名称"
    Rename-NetConnection -Name $targetVpn.Name -NewName $newVpnName
    Write-Host "已成功将VPN「$($targetVpn.Name)」重命名为「$newVpnName」"
} else {
    Write-Host "未找到ServerAddress包含「vash」的VPN连接"
}

合并为单行脚本(简化版)

如果确认只会找到一个目标VPN,也可以直接合并执行:

Get-VpnConnection | Where-Object { $_.ServerAddress -like '*vash*' } | ForEach-Object {
    Rename-NetConnection -Name $_.Name -NewName "新VPN名称"
}

内容的提问来源于stack exchange,提问作者AlexPebody

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 01:02:03