使用CreateSrsMedia.ps1创建自定义Teams Room设备时遇参数错误
解决CreateSrsMedia.ps1脚本执行Export-WindowsImage失败的问题
问题现象
使用微软官方的CreateSrsMedia.ps1脚本创建自定义Teams Room测试设备时,执行至约1462行时失败,报错提示必须指定Name或Index参数。已确认使用脚本要求的企业版ISO,install.wim为WIM格式而非ESD,更换大容量U盘后问题依旧。
错误详情
Export-WindowsImage : Either the Name or Index parameter is required At C:\teamscript\CreateSrsMedia.ps1:1462 char:9 + Export-WindowsImage -DestinationImagePath "$NewInstallWim" -S ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Export-WindowsImage], PSArgumentException + FullyQualifiedErrorId : Export-WindowsImage,Microsoft.Dism.Commands.ExportWindowsImageCommand
对应脚本片段
# Windows Write-Host "Copying Windows... " -NoNewline ## Exclude install.wim, since apparently some Windows source media are not USB EFI compatible (?) and have WIMs >4GB in size. SyncDirectory -Src $WindowsMedia -Dst $TargetDrive -Flags @("/xf", "install.wim") Write-Host "done." $NewInstallWim = (Join-Path $PSScriptRoot "install.wim") $InstallWimMnt = (Join-Path $PSScriptRoot "com-mnt") $SourceName = "Windows $MajorOs Enterprise" try { Write-Host "Copying the installation image... " -NoNewline Export-WindowsImage -DestinationImagePath "$NewInstallWim" -SourceImagePath (Join-Path (Join-Path $WindowsMedia "sources") "install.wim") -SourceName $SourceName | Write-Debug Write-Host "done." # 后续镜像处理、更新等逻辑省略 } catch { try { Dismount-WindowsImage -Path $InstallWimMnt -Discard -ErrorAction SilentlyContinue } catch {} del $InstallWimMnt -Force -ErrorAction SilentlyContinue del $NewInstallWim -Force -ErrorAction SilentlyContinue throw }
解决建议
验证源WIM镜像的实际名称
运行以下命令查看源install.wim中的所有镜像信息,确认Windows $MajorOs Enterprise是否存在:Get-WindowsImage -ImagePath "X:\sources\install.wim" # 将X替换为你的ISO挂载盘符如果实际镜像名称与脚本中的
$SourceName不匹配(比如实际是Windows 10 Enterprise或Windows 11 Enterprise,不带版本号),需修改脚本中的$SourceName变量为正确名称。改用镜像索引参数替代名称参数
若名称匹配仍报错,或想避免名称匹配问题,直接使用镜像索引替换-SourceName $SourceName参数。例如:Export-WindowsImage -DestinationImagePath "$NewInstallWim" -SourceImagePath (Join-Path (Join-Path $WindowsMedia "sources") "install.wim") -SourceIndex 1 | Write-Debug注意:索引1通常对应企业版,但需通过
Get-WindowsImage命令确认实际索引值。检查$MajorOs变量的赋值正确性
脚本中$SourceName依赖$MajorOs变量获取系统版本(如10或11),可在脚本中添加调试输出确认该变量值:Write-Host "当前MajorOs值: $MajorOs"若
$MajorOs为空或错误,会导致$SourceName无效,触发参数缺失错误。确保DISM运行环境合规
以管理员身份运行PowerShell,同时确认使用的Windows ADK版本与目标系统版本兼容,避免DISM命令的兼容性问题。
内容的提问来源于stack exchange,提问作者rbeard.js
相关产品推荐
相关产品推荐

