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

Windows 10/11下完善WLAN配置文件导入导出PowerShell脚本

批量导入WiFi配置XML文件的PowerShell实现

核心思路

批量导入的关键是遍历C:\ps目录下所有.xml后缀的配置文件,对每个文件执行单个导入命令即可。

单个导入命令回顾

先确认单个XML文件的导入命令(你已知的命令通常是):

netsh wlan add profile filename="C:\ps\WiFi-Example.xml" user=all

user=all参数会让该WiFi配置对所有用户生效,可根据需求调整。

批量导入脚本实现

以下是完整的批量导入脚本,包含文件夹检查、遍历处理和基础错误提示:

# 定义目标文件夹路径
$wifiConfigDir = "C:\ps"

# 检查文件夹是否存在
if (-not (Test-Path -Path $wifiConfigDir)) {
    Write-Host "错误:目标文件夹 $wifiConfigDir 不存在,请先确认配置文件位置。" -ForegroundColor Red
    exit 1
}

# 获取文件夹下所有XML配置文件
$xmlFiles = Get-ChildItem -Path $wifiConfigDir -Filter "*.xml" -File

# 检查是否有XML文件
if ($xmlFiles.Count -eq 0) {
    Write-Host "提示:$wifiConfigDir 下未找到任何XML配置文件。" -ForegroundColor Yellow
    exit 0
}

# 遍历所有XML文件执行导入
foreach ($file in $xmlFiles) {
    Write-Host "正在导入配置文件:$($file.Name)" -ForegroundColor Cyan
    # 执行导入命令
    $importResult = netsh wlan add profile filename="$($file.FullName)" user=all
    # 输出导入结果
    if ($importResult -match "成功") {
        Write-Host "导入 $($file.Name) 成功!" -ForegroundColor Green
    } else {
        Write-Host "导入 $($file.Name) 失败,错误信息:$importResult" -ForegroundColor Red
    }
}

Write-Host "批量导入操作完成!" -ForegroundColor Green

注意事项

  • 该脚本需要以管理员权限运行,否则会因权限不足导致导入失败。
  • 导入时如果目标设备已存在同名WiFi配置,会自动覆盖原有配置(netsh命令默认行为)。
  • 确保XML文件是通过netsh wlan export profile导出的标准格式,非标准XML可能无法导入。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 21:12:01