powershell netsh 正在导入 xml 个配置文件

powershell netsh importing xml profiles

我有以下导出所有最终用户 wifi 配置文件的脚本。

netsh wlan export profile folder="\server\%username%\Wireless"
Powershell.exe -executionpolicy unrestricted -File wireless_backup.ps1

然后使用 "wireless_backup.ps1" 将配置文件名称放入 .CSV 中。这里是 wireless_backup.ps1.

Get-ChildItem "\server$env:username\Wireless" | Select Name | Export-CSV -path '\server$env:username\Wireless'

以上所有工作正常....将这些配置文件恢复到另一台 PC 是我遇到困难的地方。这是恢复脚本。

Powershell.exe -executionpolicy unrestricted -File wireless_restore.ps1

wireless_restore.ps1 包含这段代码。

$ProfileList=IMPORT-CSV \server$env:username\Wireless\wireless.csv

FOREACH ($Profile in $ProfileList) {
netsh wlan add profile filename= $Profile.name
}

我的预期是 Wifi 配置文件会自动将自己添加到 PC。我不确定哪里出错了。请帮忙!

更新 我的老板出于某种原因不想使用 MS 用户状态迁移,但我们正在进行大规模重新映像。我需要一种方法来轻松备份以下所有内容:用户配置文件数据、chrome 书签、iTunes 备份、Outlook pst 文件、打印机、无线配置文件、Outlook 自动完成、壁纸和其他一些内容。

这是我想出的备份脚本

REM FORCE OUTLOOK CLOSED, PST FILES WILL NOT BACKUP IF IN USE
cscript "\server\outlook.vbs"

REM BACKUP USERS PROFILE
xcopy "%userprofile%" "\server\%username%\%username%" /e /y /i

REM BACKUP SIGNATURES
xcopy "%appdata%\microsoft\signatures" "\server\%username%\Signatures" /e /y /i

REM BACKUP PINNED TASKBAR ITEMS
xcopy "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" "\server\%username%\TaskBar" /e /y /i

REM BACKUP OUTLOOK ARCHIVES PST OUTLOOK MUST BE CLOSED
xcopy "C:\Users\%username%\AppData\Local\Microsoft\Outlook\*.pst" "\server\%username%\Outlook" /y /i

REM BACKUP CHROME BOOKMARKS
xcopy "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default" "\server\%username%\Chrome" /e /y /i

REM BACKUP iTUNES MOBILE BACKUPS
xcopy "C:\Users\%username%\AppData\Roaming\Apple Computer\MobileSync" "\server\%username%\MobileSync" /e /y /i

REM BACKUP ADVANCED COLOR SETTINGS
REG EXPORT "HKCU\Control Panel\Colors" "\server\%username%\Wallpaper\Colors1.reg" /y

REM BACKUP ADVANCED COLOR SETTINGS
REG EXPORT "HKCU\Control Panel\Desktop\Colors" "\server\%username%\Wallpaper\Colors2.reg" /y

REM BACKUP DESKTOP BG SETTINGS
REG EXPORT "HKCU\Control Panel\Desktop\WindowMetrics" "\server\%username%\Wallpaper\WindowMetrics_Backup.reg" /y

REM START WALLPAPER BACKUP SCRIPT
Powershell.exe -executionpolicy remotesigned -File "wallpaper.ps1"

    wallpaper.ps1 looks like this
    $wallpaper = (Get-ItemProperty 'hkcu:\control panel\desktop\' -Name Wallpaper).Wallpaper
    xcopy $wallpaper "\itmdtren\z$\backup$env:username\Wallpaper\"

REM EXPORTS ALL CURRENTLY INSTALLED PRINTERS TO CSV
Powershell.exe -executionpolicy unrestricted -File "\itmdtren\z$\backup scripts\print_backup.ps1"

    printer_backup.ps1 looks like this
    Get-WMIObject -class Win32_Printer -computer $env:computername | Select Name | Export-CSV

REM EXPORT ALL XML WLAN PROFILES TO BACKUP
netsh wlan export profile folder="\itmdtren\z$\backup\%username%\Wireless"

REM EXPORTS NAMES OF ALL WLAN PROFILES TO CSV
Powershell.exe -executionpolicy unrestricted -File "\itmdtren\z$\backup scripts\wireless_backup.ps1"

    wireless_backup.ps1 looks like this
    Get-ChildItem "\itmdtren\z$\backup$env:username\Wireless" | Select Name | Export-CSV -path '\itmdtren\z$\backup$env:username\Wireless\wireless.csv'

在我对计算机进行映像后,我以用户身份登录并运行执行以下脚本。这就是您的答案有帮助的地方!如您所见,wifi 配置文件导出脚本是上面显示的打印机备份脚本的修改版本。

REM FORCE OUTLOOK CLOSED
cscript "\itmdtren\z$\backup scripts\outlook.vbs"

REM RESTORE USERS PROFILE
xcopy "\itmdtren\z$\backup\%username%\%username%" "%userprofile%" /e /y /i

REM RESTORE SIGNATURES
xcopy "\itmdtren\z$\backup\%username%\Signatures" "%appdata%\microsoft\signatures" /e /y /i

REM THIS LINE NOT USED RESTORE TASKBAR
REM xcopy "\itmdtren\z$\backup\%username%\TaskBar" "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" /e /y /i

REM RESTORE OUTLOOK DATA FILES PST
xcopy "\itmdtren\z$\backup\%username%\Outlook\*.pst" "C:\Users\%username%\Documents\Outlook Files" /y /i

REM RESTORE USER DEFAULT CHROME BOOKMARKS/SETTINGS
xcopy "\itmdtren\z$\backup\%username%\Chrome" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default" /e /y /i

REM RESTORE ITUENS BACKUPS
xcopy "\itmdtren\z$\backup\%username%\MobileSync" "C:\Users\%username%\AppData\Roaming\Apple Computer\MobileSync" /e /y /i

REM RESTORE ADVANCED DISPLAY SETTINGS
REG import "\itmdtren\z$\backup\%username%\Wallpaper\Colors1.reg"
REG import "\itmdtren\z$\backup\%username%\Wallpaper\Colors2.reg"
REG import "\itmdtren\z$\backup\%username%\Wallpaper\WindowMetrics_Backup.reg"

REM wallpaperchanger.exe IS A COMMANDLINE UTILITY THAT RANDOMLY SELECTS A IMAGE FROM A FOLDER, CONVERTS TO BMP, COPIES TO USER PROFILE AND SETS BACKGROUD
"\itmdtren\z$\backup scripts\WallpaperChanger.exe" "\itmdtren\z$\backup\%username%\Wallpaper" 2 "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Themes"

REM FORCE UPDATE USER SYSTEM PARAMETERS
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters

REM RESTORE PRINTERS FROM CSV
Powershell.exe -executionpolicy unrestricted -File "\itmdtren\z$\backup scripts\print_restore.ps1"

    print_restore.ps1 looks like this
    $PrinterList=IMPORT-CSV \itmdtren\z$\backup$env:username\Printers\printer_export.csv

    FOREACH ($Printer in $PrinterList) {
    Start-Sleep -s 10
    Invoke-Expression 'rundll32 printui.dll PrintUIEntry /in /q /n $($Printer.Name)'
    }

REM RESTORE XML WLAN PROFILES FROM CSV
Powershell.exe -executionpolicy unrestricted -File "\itmdtren\z$\backup scripts\wireless_restore.ps1"

    wireless_restore.ps1 looks like this
    $ProfileList=IMPORT-CSV \itmdtren\z$\backup$env:username\Wireless\wireless.csv

    FOREACH ($Profile in $ProfileList) {
    $fullname = Join-Path "\itmdtren\z$\backup$env:username\Wireless" $profile.name
    netsh wlan add profile filename= $fullname
    }

这是脚本完成后用户备份的样子

如您所见,确实导出了所有 XML 无线配置文件,并且 powershell 脚本将所有这些文件的名称放入 csv 中。

这是 csv 的样子

powershell 脚本不适用于本地打印机,但我们可以使用 printbrm.exe 来支持驱动程序。它确实适用于所有网络打印机。

恢复脚本毫无问题地将所有这些恢复到新映像的 PC 上,这一切都归功于 Whosebug 的成员!

$Profile.Name 不够,你应该提供完整的 unc 路径,

试试这个

FOREACH ($Profile in $ProfileList) {
$fullname = Join-Path "\server$env:username\Wireless" $profile.name
netsh wlan add profile filename= $fullname
}

我仍然需要测试,但我认为我与 Avshalom 就此问题的根源进行了测试。名称只是一个文件名和扩展名。它不是完整的文件路径,您应该使用它来获得一致的结果。如果您的 PowerShell 会话中的当前目录是 \server\%username%\Wireless,那么您 可能 没有问题。

未经测试,因为我在这台计算机上没有无线配置文件,我建议您一起取消 CSV,因为无论如何您只想要一件事。我不知道这是否是一个拼写错误,但您导出的并不是您真正想要的路径。在您的恢复脚本中,您使用 \server$env:username\Wireless\wireless.txt,但在您的备份脚本中,我们看到 \server$env:username\Wireless。假设您拥有权限,您会在 \server$env:username.

下看到文件调用 "Wireless"

wireless_backup.ps1

Get-ChildItem "\server$env:username\Wireless" | Select-Object -Expand FullName | Set-Content -path '\server$env:username\Wireless\wireless.txt'

wireless_restore.ps1

$ProfileList=Get-Content \server$env:username\Wireless\wireless.txt

FOREACH ($Profile in $ProfileList) {
    netsh wlan add profile filename=$Profile
}

仅供参考,我不知道(但正在查找)这是否是导出无线配置文件的合适方式。