diff --git a/README.md b/README.md index a98f4ef..f3dd5a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # UnattendTool 简介 * 生成 Windows 系统自动安装应答文件 Unattend.xml -* 可搭配 Ventoy 一起使用:https://github.com/ventoy/Ventoy +* 支持 Ventoy * 只支持 Windows 10 或 Windows 11 # 下载 @@ -10,9 +10,37 @@ > https://github.com/dsx42/UnattendTool/releases -# 使用 +# 如何使用本工具? -解压,鼠标左键双击运行解压后的 `UnattendTool.cmd` 文件,根据提示操作即可 +有如下两种使用场景: + +## 当前电脑要安装系统 + +* 在当前电脑安装系统前,把下载的文件解压到当前电脑 +* 鼠标左键双击运行解压后的 `UnattendTool.cmd` 文件,根据提示操作 + * 提示包含当前电脑的信息,可以直接参考 + +## 其他电脑要安装系统 + +* 把下载的文件解压到当前电脑 +* 鼠标左键双击运行解压后的 `UnattendTool.cmd` 文件,根据提示操作 + * 提示包含当前电脑的信息,不是将要安装系统的电脑信息,不可以作为参考 + * 必须了解要安装系统的电脑信息,并合理设置 + +# 生成的应答文件在哪里? + +* 默认情况下,在 `%userprofile%\Desktop\ventoy\script\` 目录下 +* 若指定了应答文件目录,则在指定目录下的 `ventoy\script\` 目录下 + +# 生成的应答文件如何使用? + +## 和 Venoty 一起使用 + +* 准备一个 U 盘,用 Ventoy 处理,详见:https://www.ventoy.net/cn/doc_start.html +* 把应答文件复制到 U 盘 +* 修改 U 盘下的 Ventoy 配置文件 `ventoy\ventoy.json`,详见:https://www.ventoy.net/cn/plugin_autoinstall.html +* U 盘插入要安装系统的电脑,该电脑关机,进入 BIOS,修改为启动进入 U 盘 +* 进入 Ventoy 选择镜像的页面,选择要安装的镜像,选择要使用的应答文件 # 支持的选项 @@ -34,6 +62,7 @@ [-Architecture String] [-DiskId int] [-PartitionID int] + [-PartitionStyle String] [-FullName String] [-VentoyDriverLetter String] [-ISOPath String] @@ -60,6 +89,9 @@ * `'x86'`:32 位系统;注意,Windows 11 只有 64 位系统 * `-DiskId int`:要安装系统的硬盘编号,硬盘编号从 0 开始;默认为 -1,表示自动选择当前操作系统所在的硬盘 * `-PartitionID int`:要安装系统的分区编号,分区编号从 1 开始;默认为 -1,表示自动选择当前操作系统所在的分区 +* `-PartitionStyle String`:未指定 `-NotFormat` 时,需要指定该参数,表示要安装系统的硬盘的分区类型,只支持如下两个值: + * `GPT`:GPT 分区;默认值 + * `MBR`:MBR 分区 * `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'` * `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面 * `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定 @@ -67,6 +99,8 @@ # 参考资料 -> Windonws 11 应答文件必须的内容:https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/automate-windows-setup?view=windows-11 -> 应答文件组件介绍:https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/components-b-unattend -> 在线应答文件生成器:https://www.windowsafg.com/index.html +* Windonws 11 应答文件必须的内容:https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/automate-windows-setup?view=windows-11 +* 应答文件组件介绍:https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/components-b-unattend +* 在线应答文件生成器:https://www.windowsafg.com/index.html +* Ventoy 使用:https://www.ventoy.net/cn/doc_start.html +* Ventoy 自动安装:https://www.ventoy.net/cn/plugin_autoinstall.html diff --git a/UnattendTool.ps1 b/UnattendTool.ps1 index 8a6354d..2aa38ef 100644 --- a/UnattendTool.ps1 +++ b/UnattendTool.ps1 @@ -4,7 +4,8 @@ $WindowsProductName = 'Enterprise', $Architecture = 'x64', $DiskId = -1, - $PartitionID = -1, + $PartitionId = -1, + $PartitionStyle = 'GPT', $FullName = 'MyPC', $VentoyDriverLetter = '', $ISOPath = '', @@ -502,7 +503,7 @@ function ShowIsBoot { if ($SelectPartition['Type'] -ieq 'Primary') { Write-Host -Object '' $SelectPartition['IsBoot'] = $true - $Script:PartitionID = $SelectPartition['Order'] + $Script:PartitionId = $SelectPartition['Order'] return } else { @@ -720,6 +721,48 @@ function ShowFomatSelect { } } +function ShowPartitionStyleSelect { + param($DiskId) + + $CurrentDisks = GetCurrentDisk + $SelectDisk = $CurrentDisks[$DiskId] + $DefalultSelect = 1 + $DefaultPartitionStyle = 'GPT' + if ($SelectDisk -and $SelectDisk['PartitionStyle'] -ine 'GPT') { + $DefalultSelect = 2 + $DefaultPartitionStyle = 'MBR' + } + + Write-Host -Object '====================================' + Write-Host -Object "请确认所选硬盘分区的分区类型,推荐 $DefalultSelect" + Write-Host -Object '====================================' + Write-Host -Object '' + Write-Host -Object '1: GPT 分区' + Write-Host -Object '' + Write-Host -Object '2: MBR 分区' + + while ($true) { + Write-Host -Object '' + $InputOption = Read-Host -Prompt "请输入选择的序号(默认为 $DefalultSelect),按回车键确认" + if ($InputOption -ieq '') { + Write-Host -Object '' + return $DefaultPartitionStyle + } + if ($InputOption -ieq '1') { + Write-Host -Object '' + return 'GPT' + } + elseif ($InputOption -ieq '2') { + Write-Host -Object '' + return 'MBR' + } + else { + Write-Host -Object '' + Write-Warning -Message '选择无效,请重新输入' + } + } +} + function ShowNameInput { Write-Host -Object '==================================================' @@ -1061,8 +1104,11 @@ if ($Interactive) { $CreatePartitionInfo = ShowCreatePartition } else { - $PartitionID = ShowPartitionIdSelect -DiskId $DiskId + $PartitionId = ShowPartitionIdSelect -DiskId $DiskId $NotFormat = !$(ShowFomatSelect) + if (!$NotFormat) { + $PartitionStyle = ShowPartitionStyleSelect -DiskId $DiskId + } } $FullName = ShowNameInput $VentoyDriverLetter = ShowVentoyDriverLetterSelect @@ -1118,8 +1164,19 @@ if ($DiskId -eq -1) { $DiskId = GetSystemDiskId } -if ($PartitionID -eq -1) { - $PartitionID = GetSystemPartitionId +if ($PartitionId -eq -1) { + $PartitionId = GetSystemPartitionId +} + +if ($PartitionStyle -ine 'GPT' -and $PartitionStyle -ine 'MBR') { + Write-Warning -Message '参数 PartitionStyle 只支持 GPT, MBR' + [System.Environment]::Exit(0) +} +if ($PartitionStyle -ieq 'GPT') { + $PartitionStyle = 'GPT' +} +elseif ($PartitionStyle -ieq 'MBR') { + $PartitionStyle = 'MBR' } if ('' -ieq $VentoyDriverLetter) { @@ -1148,10 +1205,13 @@ if (!$(Test-Path -Path $VentoyConfigScriptPath -PathType Container)) { $DiskTypeStr = '' if ($WipeDisk -eq 1) { - $DiskTypeStr = '_GPT' + $DiskTypeStr = '_CreateGPT' } elseif ($WipeDisk -eq 2) { - $DiskTypeStr = '_MBR' + $DiskTypeStr = '_CreateMBR' +} +elseif (!$NotFormat) { + $DiskTypeStr = "_Format$PartitionStyle" } $ProductInfo = @{} if ('' -ieq $WindowsProductName) { @@ -1180,13 +1240,7 @@ Add-Content -Path $UnattendPath -Value (" ' Add-Content -Path $UnattendPath -Value " $Language" Add-Content -Path $UnattendPath -Value ' ' -if ('zh-CN' -eq $Language) { - Add-Content -Path $UnattendPath -Value (' 0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}' + ` - '{FA550B04-5AD7-411f-A5AC-CA038EC515D7}') -} -else { - Add-Content -Path $UnattendPath -Value ' 0409:00000409' -} +Add-Content -Path $UnattendPath -Value " $Language" Add-Content -Path $UnattendPath -Value " $Language" Add-Content -Path $UnattendPath -Value " $Language" Add-Content -Path $UnattendPath -Value " $Language" @@ -1208,7 +1262,6 @@ if ($WindowsProductName) { $key = $ProductInfo['gvlk'] Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value " $key" - Add-Content -Path $UnattendPath -Value ' Never' Add-Content -Path $UnattendPath -Value ' ' } Add-Content -Path $UnattendPath -Value ' ' @@ -1265,8 +1318,12 @@ elseif (!$NotFormat) { Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' + if ($PartitionStyle -ieq 'MBR') { + Add-Content -Path $UnattendPath -Value ' true' + } Add-Content -Path $UnattendPath -Value ' NTFS' - Add-Content -Path $UnattendPath -Value " $PartitionID" + Add-Content -Path $UnattendPath -Value ' 1' + Add-Content -Path $UnattendPath -Value " $PartitionId" Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' @@ -1276,12 +1333,7 @@ elseif (!$NotFormat) { Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' if ($WindowsProductName) { - if ($Language -ieq 'zh-CN') { - $ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['CN'] - } - else { - $ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['US'] - } + $ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['US'] Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' /IMAGE/NAME' @@ -1293,7 +1345,7 @@ if ($WindowsProductName) { Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value " $DiskId" -Add-Content -Path $UnattendPath -Value " $PartitionID" +Add-Content -Path $UnattendPath -Value " $PartitionId" Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' @@ -1301,23 +1353,6 @@ Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' ' -Add-Content -Path $UnattendPath -Value (" ") -if ('zh-CN' -eq $Language) { - Add-Content -Path $UnattendPath -Value (' 0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}' + ` - '{FA550B04-5AD7-411f-A5AC-CA038EC515D7}') -} -else { - Add-Content -Path $UnattendPath -Value ' 0409:00000409' -} -Add-Content -Path $UnattendPath -Value " $Language" -Add-Content -Path $UnattendPath -Value " $Language" -Add-Content -Path $UnattendPath -Value " $Language" -Add-Content -Path $UnattendPath -Value " $Language" -Add-Content -Path $UnattendPath -Value ' ' -Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value (" ' Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' ' +Add-Content -Path $UnattendPath -Value (" ") +Add-Content -Path $UnattendPath -Value " $Language" +Add-Content -Path $UnattendPath -Value " $Language" +Add-Content -Path $UnattendPath -Value " $Language" +Add-Content -Path $UnattendPath -Value " $Language" +Add-Content -Path $UnattendPath -Value " $Language" +Add-Content -Path $UnattendPath -Value ' ' +Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value (" true' Add-Content -Path $UnattendPath -Value ' 3' Add-Content -Path $UnattendPath -Value ' ' -Add-Content -Path $UnattendPath -Value '' -if ($Language -ieq 'zh-CN') { - Add-Content -Path $UnattendPath -Value ' China Standard Time' -} -else { - Add-Content -Path $UnattendPath -Value ' Pacific Standard Time' -} Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value '' @@ -1397,3 +1436,4 @@ Add-Content -Path $UnattendPath -Value '' Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath) Write-Host -Object '' Read-Host -Prompt '按回车键关闭此窗口' + diff --git a/product.json b/product.json index 03662ef..8590540 100644 --- a/product.json +++ b/product.json @@ -1,6 +1,6 @@ { "name": "UnattendTool", - "version": "2022.6.27", + "version": "2022.6.30", "files": [ "UnattendTool.cmd", "UnattendTool.ps1",