diff --git a/README.md b/README.md index 4b47270..a98f4ef 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,9 @@ * `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面 * `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定 * `-NotFormat`:安装系统时不格式化所选硬盘分区;默认安装时会格式化所选硬盘分区 + +# 参考资料 + +> 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 diff --git a/UnattendTool.ps1 b/UnattendTool.ps1 index 0c6da9a..8a6354d 100644 --- a/UnattendTool.ps1 +++ b/UnattendTool.ps1 @@ -393,43 +393,46 @@ function ShowWipeDiskSelect { $CurrentDisks = GetCurrentDisk $SelectDisk = $CurrentDisks[$DiskId] - $DefaultWipe = $false - $DefalultSelect = 2 + $DefalultSelect = 0 if ($SelectDisk -and $SelectDisk['PartitionStyle'] -ine 'GPT') { - Write-Host -Object '======================================================================' - Write-Host -Object '选择是否对所选硬盘进行 GPT 分区,所选系统只支持 GPT 分区的硬盘,推荐 2' - Write-Host -Object '======================================================================' - $DefaultWipe = $true - $DefalultSelect = 2 + Write-Host -Object '==================================' + Write-Host -Object '选择是否对所选硬盘进行分区,推荐 1' + Write-Host -Object '==================================' + $DefalultSelect = 1 } else { - Write-Host -Object '======================================================================' - Write-Host -Object '选择是否对所选硬盘进行 GPT 分区,所选系统只支持 GPT 分区的硬盘,推荐 1' - Write-Host -Object '======================================================================' - $DefaultWipe = $false - $DefalultSelect = 1 + Write-Host -Object '==================================' + Write-Host -Object '选择是否对所选硬盘进行分区,推荐 0' + Write-Host -Object '==================================' + $DefalultSelect = 0 } Write-Host -Object '' - Write-Host -Object '1: 否' + Write-Host -Object '0: 否' + Write-Host -Object '' + Write-Host -Object '1: GPT 分区,注意:安装系统时会清除所选硬盘的数据,请及时备份所选硬盘的数据' -ForegroundColor Red Write-Host -Object '' - Write-Host -Object '2: 是,注意:安装系统时会清除所选硬盘的数据,请及时备份所选硬盘的数据' -ForegroundColor Red + Write-Host -Object '2: MBR 分区,注意:安装系统时会清除所选硬盘的数据,请及时备份所选硬盘的数据' -ForegroundColor Red while ($true) { Write-Host -Object '' $InputOption = Read-Host -Prompt "请输入选择的序号(默认为 $DefalultSelect),按回车键确认" if ($InputOption -ieq '') { Write-Host -Object '' - return $DefaultWipe + return $DefalultSelect + } + elseif ('0' -ieq $InputOption) { + Write-Host -Object '' + return 0 } elseif ($InputOption -ieq '1') { Write-Host -Object '' - return $false + return 1 } elseif ($InputOption -ieq '2') { Write-Host -Object '' - return $true + return 2 } else { Write-Host -Object '' @@ -518,35 +521,43 @@ function ShowIsBoot { function ShowCreatePartition { - $CreatePartitionInfo = [ordered]@{ - '1' = @{ - 'Order' = 1; - 'Size' = 300; - 'Type' = 'EFI'; - 'TypeName' = 'EFI 分区'; - 'FileSystem' = 'FAT32'; - 'Extend' = $false; - 'IsHidden' = $true; - 'IsBoot' = $false - }; - '2' = @{ - 'Order' = 2; - 'Size' = 200; - 'Type' = 'MSR'; - 'TypeName' = '微软保留分区'; - 'FileSystem' = ''; - 'Extend' = $false; - 'IsHidden' = $true; - 'IsBoot' = $false + if (1 -eq $script:WipeDisk) { + $CreatePartitionInfo = [ordered]@{ + '1' = @{ + 'Order' = 1; + 'Size' = 100; + 'Type' = 'EFI'; + 'TypeName' = 'EFI 分区'; + 'FileSystem' = 'FAT32'; + 'Extend' = $false; + 'IsHidden' = $true; + 'IsBoot' = $false + }; + '2' = @{ + 'Order' = 2; + 'Size' = 128; + 'Type' = 'MSR'; + 'TypeName' = '微软保留分区'; + 'FileSystem' = ''; + 'Extend' = $false; + 'IsHidden' = $true; + 'IsBoot' = $false + } } + $PartitionNumber = 2 + Write-Host -Object '===============' + Write-Host -Object '创建新 GPT 分区' + Write-Host -Object '===============' + Write-Host -Object '' + } + else { + $CreatePartitionInfo = [ordered]@{} + $PartitionNumber = 0 + Write-Host -Object '======================================' + Write-Host -Object '创建新 MBR 分区,最多支持创建 4 个分区' + Write-Host -Object '======================================' + Write-Host -Object '' } - - Write-Host -Object '==========' - Write-Host -Object '创建新分区' - Write-Host -Object '==========' - Write-Host -Object '' - - $PartitionNumber = 2 ShowNewPartition -CreatePartitionInfo $CreatePartitionInfo @@ -591,7 +602,12 @@ function ShowCreatePartition { Write-Host -Object '' continue } - $ShowAddNewPartition = ShowAddNewPartition + if (2 -eq $script:WipeDisk -and $PartitionNumber -ge 4) { + $ShowAddNewPartition = $false + } + else { + $ShowAddNewPartition = ShowAddNewPartition + } if (!$ShowAddNewPartition) { $CreatePartitionInfo["$PartitionNumber"]['Extend'] = $true break @@ -997,7 +1013,7 @@ Set-Location -Path $PSScriptRoot Write-Host -Object "=====> Windows 系统自动安装应答文件生成 v$VersionInfo <=====" Write-Host -Object '' -$WipeDisk = $false +$WipeDisk = 0 $Token = '31bf3856ad364e35' $WindowsProduct = [ordered]@{ 'Enterprise' = @{ @@ -1041,7 +1057,7 @@ if ($Interactive) { $Architecture = ShowArchitectureSelect -OsVersion $OsVersion $DiskId = ShowDiskIdSelect $WipeDisk = ShowWipeDiskSelect -DiskId $DiskId - if ($WipeDisk) { + if (1 -eq $WipeDisk -or 2 -eq $WipeDisk) { $CreatePartitionInfo = ShowCreatePartition } else { @@ -1130,16 +1146,23 @@ if (!$(Test-Path -Path $VentoyConfigScriptPath -PathType Container)) { New-Item -Path $VentoyConfigScriptPath -ItemType Directory -Force | Out-Null } +$DiskTypeStr = '' +if ($WipeDisk -eq 1) { + $DiskTypeStr = '_GPT' +} +elseif ($WipeDisk -eq 2) { + $DiskTypeStr = '_MBR' +} $ProductInfo = @{} if ('' -ieq $WindowsProductName) { $UnattendPath = $VentoyConfigScriptPath + '\Unattend_Windows_' + $OsVersion + '_' + $Architecture + '_' ` - + $Language + '_' + $FullName + '.xml' + + $Language + $DiskTypeStr + '_' + $FullName + '.xml' } else { $ProductInfo = $WindowsProduct[$WindowsProductName] $NoSpaceName = $ProductInfo['NoSpaceName'] $UnattendPath = $VentoyConfigScriptPath + '\Unattend_Windows_' + $OsVersion + '_' + $NoSpaceName + '_' ` - + $Architecture + '_' + $Language + '_' + $FullName + '.xml' + + $Architecture + '_' + $Language + $DiskTypeStr + '_' + $FullName + '.xml' } UpdateVentoyConfig -ISOPath $ISOPath -UnattendPath $UnattendPath -VentoyConfigParentPath $VentoyConfigParentPath @@ -1157,10 +1180,17 @@ Add-Content -Path $UnattendPath -Value (" ' Add-Content -Path $UnattendPath -Value " $Language" Add-Content -Path $UnattendPath -Value ' ' -Add-Content -Path $UnattendPath -Value " $Language" +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 (" $key" + 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 ' ' Add-Content -Path $UnattendPath -Value '' -if ($WipeDisk) { +if ($WipeDisk -ne 0) { Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value ' ' Add-Content -Path $UnattendPath -Value " $DiskId" @@ -1189,7 +1222,7 @@ if ($WipeDisk) { Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' ' $CreatePartitionInfo.GetEnumerator() | ForEach-Object { - Add-Content -Path $UnattendPath -Value ' ' + Add-Content -Path $UnattendPath -Value ' ' if ($_.Value['Extend']) { Add-Content -Path $UnattendPath -Value ' true' } @@ -1207,7 +1240,10 @@ if ($WipeDisk) { Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' ' $CreatePartitionInfo.GetEnumerator() | ForEach-Object { - Add-Content -Path $UnattendPath -Value ' ' + Add-Content -Path $UnattendPath -Value ' ' + if ($WipeDisk -eq 2 -and $_.Value['IsBoot']) { + Add-Content -Path $UnattendPath -Value ' true' + } $Format = $_.Value['FileSystem'] if ($Format) { Add-Content -Path $UnattendPath -Value " $Format" @@ -1215,8 +1251,6 @@ if ($WipeDisk) { $Order = $_.Value['Order'] Add-Content -Path $UnattendPath -Value " $Order" Add-Content -Path $UnattendPath -Value " $Order" - $Type = $_.Value['Type'] - Add-Content -Path $UnattendPath -Value " $Type" Add-Content -Path $UnattendPath -Value ' ' } Add-Content -Path $UnattendPath -Value ' ' @@ -1230,7 +1264,7 @@ elseif (!$NotFormat) { Add-Content -Path $UnattendPath -Value " $DiskId" 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 ' NTFS' Add-Content -Path $UnattendPath -Value " $PartitionID" Add-Content -Path $UnattendPath -Value ' ' @@ -1266,15 +1300,71 @@ 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 (" ") +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 ' true' +Add-Content -Path $UnattendPath -Value ' ' +Add-Content -Path $UnattendPath -Value '' +Add-Content -Path $UnattendPath -Value (" ") +Add-Content -Path $UnattendPath -Value ' 0' +Add-Content -Path $UnattendPath -Value ' ' +if ($WindowsProductName) { + $key = $ProductInfo['gvlk'] + Add-Content -Path $UnattendPath -Value '' + Add-Content -Path $UnattendPath -Value (" ") + Add-Content -Path $UnattendPath -Value " $key" + 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 ($FullName) { + Add-Content -Path $UnattendPath -Value ' ' + Add-Content -Path $UnattendPath -Value ' ' + Add-Content -Path $UnattendPath -Value ' ' + Add-Content -Path $UnattendPath -Value ' true</PlainText>' + Add-Content -Path $UnattendPath -Value ' </Password>' + Add-Content -Path $UnattendPath -Value ' <Enabled>true</Enabled>' + Add-Content -Path $UnattendPath -Value " <Username>$FullName</Username>" + Add-Content -Path $UnattendPath -Value ' </AutoLogon>' + Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ' <UserAccounts>' Add-Content -Path $UnattendPath -Value ' <LocalAccounts>' Add-Content -Path $UnattendPath -Value ' <LocalAccount wcm:action="add">' + Add-Content -Path $UnattendPath -Value ' <Password>' + Add-Content -Path $UnattendPath -Value ' <Value/>' + Add-Content -Path $UnattendPath -Value ' <PlainText>true</PlainText>' + Add-Content -Path $UnattendPath -Value ' </Password>' Add-Content -Path $UnattendPath -Value " <DisplayName>$FullName</DisplayName>" Add-Content -Path $UnattendPath -Value ' <Group>Administrators</Group>' Add-Content -Path $UnattendPath -Value " <Name>$FullName</Name>" @@ -1282,6 +1372,8 @@ if ($FullName) { Add-Content -Path $UnattendPath -Value ' </LocalAccounts>' Add-Content -Path $UnattendPath -Value ' </UserAccounts>' Add-Content -Path $UnattendPath -Value '' + Add-Content -Path $UnattendPath -Value " <RegisteredOwner>$FullName</RegisteredOwner>" + Add-Content -Path $UnattendPath -Value '' } Add-Content -Path $UnattendPath -Value ' <OOBE>' Add-Content -Path $UnattendPath -Value ' <HideEULAPage>true</HideEULAPage>' @@ -1291,6 +1383,13 @@ Add-Content -Path $UnattendPath -Value ' <HideWirelessSetupInOOBE Add-Content -Path $UnattendPath -Value ' <HideLocalAccountScreen>true</HideLocalAccountScreen>' Add-Content -Path $UnattendPath -Value ' <ProtectYourPC>3</ProtectYourPC>' Add-Content -Path $UnattendPath -Value ' </OOBE>' +Add-Content -Path $UnattendPath -Value '' +if ($Language -ieq 'zh-CN') { + Add-Content -Path $UnattendPath -Value ' <TimeZone>China Standard Time</TimeZone>' +} +else { + Add-Content -Path $UnattendPath -Value ' <TimeZone>Pacific Standard Time</TimeZone>' +} Add-Content -Path $UnattendPath -Value ' </component>' Add-Content -Path $UnattendPath -Value ' </settings>' Add-Content -Path $UnattendPath -Value '</unattend>' diff --git a/product.json b/product.json index 1e503ae..03662ef 100644 --- a/product.json +++ b/product.json @@ -1,6 +1,6 @@ { "name": "UnattendTool", - "version": "2022.6.16", + "version": "2022.6.27", "files": [ "UnattendTool.cmd", "UnattendTool.ps1",