Browse Source

修复版本选择,输入法选择,国家选择需要手工确认的问题

main v2022.6.30
dsx42 3 years ago
parent
commit
240ff85b2d
  1. 46
      README.md
  2. 134
      UnattendTool.ps1
  3. 2
      product.json

46
README.md

@ -1,7 +1,7 @@
# UnattendTool 简介 # UnattendTool 简介
* 生成 Windows 系统自动安装应答文件 Unattend.xml * 生成 Windows 系统自动安装应答文件 Unattend.xml
* 可搭配 Ventoy 一起使用:https://github.com/ventoy/Ventoy * 支持 Ventoy
* 只支持 Windows 10 或 Windows 11 * 只支持 Windows 10 或 Windows 11
# 下载 # 下载
@ -10,9 +10,37 @@
> https://github.com/dsx42/UnattendTool/releases > 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] [-Architecture String]
[-DiskId int] [-DiskId int]
[-PartitionID int] [-PartitionID int]
[-PartitionStyle String]
[-FullName String] [-FullName String]
[-VentoyDriverLetter String] [-VentoyDriverLetter String]
[-ISOPath String] [-ISOPath String]
@ -60,6 +89,9 @@
* `'x86'`:32 位系统;注意,Windows 11 只有 64 位系统 * `'x86'`:32 位系统;注意,Windows 11 只有 64 位系统
* `-DiskId int`:要安装系统的硬盘编号,硬盘编号从 0 开始;默认为 -1,表示自动选择当前操作系统所在的硬盘 * `-DiskId int`:要安装系统的硬盘编号,硬盘编号从 0 开始;默认为 -1,表示自动选择当前操作系统所在的硬盘
* `-PartitionID int`:要安装系统的分区编号,分区编号从 1 开始;默认为 -1,表示自动选择当前操作系统所在的分区 * `-PartitionID int`:要安装系统的分区编号,分区编号从 1 开始;默认为 -1,表示自动选择当前操作系统所在的分区
* `-PartitionStyle String`:未指定 `-NotFormat` 时,需要指定该参数,表示要安装系统的硬盘的分区类型,只支持如下两个值:
* `GPT`:GPT 分区;默认值
* `MBR`:MBR 分区
* `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'` * `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'`
* `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面 * `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面
* `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定 * `-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 * 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://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/components-b-unattend
> 在线应答文件生成器:https://www.windowsafg.com/index.html * 在线应答文件生成器:https://www.windowsafg.com/index.html
* Ventoy 使用:https://www.ventoy.net/cn/doc_start.html
* Ventoy 自动安装:https://www.ventoy.net/cn/plugin_autoinstall.html

134
UnattendTool.ps1

@ -4,7 +4,8 @@
$WindowsProductName = 'Enterprise', $WindowsProductName = 'Enterprise',
$Architecture = 'x64', $Architecture = 'x64',
$DiskId = -1, $DiskId = -1,
$PartitionID = -1, $PartitionId = -1,
$PartitionStyle = 'GPT',
$FullName = 'MyPC', $FullName = 'MyPC',
$VentoyDriverLetter = '', $VentoyDriverLetter = '',
$ISOPath = '', $ISOPath = '',
@ -502,7 +503,7 @@ function ShowIsBoot {
if ($SelectPartition['Type'] -ieq 'Primary') { if ($SelectPartition['Type'] -ieq 'Primary') {
Write-Host -Object '' Write-Host -Object ''
$SelectPartition['IsBoot'] = $true $SelectPartition['IsBoot'] = $true
$Script:PartitionID = $SelectPartition['Order'] $Script:PartitionId = $SelectPartition['Order']
return return
} }
else { 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 { function ShowNameInput {
Write-Host -Object '==================================================' Write-Host -Object '=================================================='
@ -1061,8 +1104,11 @@ if ($Interactive) {
$CreatePartitionInfo = ShowCreatePartition $CreatePartitionInfo = ShowCreatePartition
} }
else { else {
$PartitionID = ShowPartitionIdSelect -DiskId $DiskId $PartitionId = ShowPartitionIdSelect -DiskId $DiskId
$NotFormat = !$(ShowFomatSelect) $NotFormat = !$(ShowFomatSelect)
if (!$NotFormat) {
$PartitionStyle = ShowPartitionStyleSelect -DiskId $DiskId
}
} }
$FullName = ShowNameInput $FullName = ShowNameInput
$VentoyDriverLetter = ShowVentoyDriverLetterSelect $VentoyDriverLetter = ShowVentoyDriverLetterSelect
@ -1118,8 +1164,19 @@ if ($DiskId -eq -1) {
$DiskId = GetSystemDiskId $DiskId = GetSystemDiskId
} }
if ($PartitionID -eq -1) { if ($PartitionId -eq -1) {
$PartitionID = GetSystemPartitionId $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) { if ('' -ieq $VentoyDriverLetter) {
@ -1148,10 +1205,13 @@ if (!$(Test-Path -Path $VentoyConfigScriptPath -PathType Container)) {
$DiskTypeStr = '' $DiskTypeStr = ''
if ($WipeDisk -eq 1) { if ($WipeDisk -eq 1) {
$DiskTypeStr = '_GPT' $DiskTypeStr = '_CreateGPT'
} }
elseif ($WipeDisk -eq 2) { elseif ($WipeDisk -eq 2) {
$DiskTypeStr = '_MBR' $DiskTypeStr = '_CreateMBR'
}
elseif (!$NotFormat) {
$DiskTypeStr = "_Format$PartitionStyle"
} }
$ProductInfo = @{} $ProductInfo = @{}
if ('' -ieq $WindowsProductName) { if ('' -ieq $WindowsProductName) {
@ -1180,13 +1240,7 @@ Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Win
Add-Content -Path $UnattendPath -Value ' <SetupUILanguage>' Add-Content -Path $UnattendPath -Value ' <SetupUILanguage>'
Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>" Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>"
Add-Content -Path $UnattendPath -Value ' </SetupUILanguage>' Add-Content -Path $UnattendPath -Value ' </SetupUILanguage>'
if ('zh-CN' -eq $Language) { Add-Content -Path $UnattendPath -Value " <InputLocale>$Language</InputLocale>"
Add-Content -Path $UnattendPath -Value (' <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}' + `
'{FA550B04-5AD7-411f-A5AC-CA038EC515D7}</InputLocale>')
}
else {
Add-Content -Path $UnattendPath -Value ' <InputLocale>0409:00000409</InputLocale>'
}
Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>" Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>"
Add-Content -Path $UnattendPath -Value " <SystemLocale>$Language</SystemLocale>" Add-Content -Path $UnattendPath -Value " <SystemLocale>$Language</SystemLocale>"
Add-Content -Path $UnattendPath -Value " <UserLocale>$Language</UserLocale>" Add-Content -Path $UnattendPath -Value " <UserLocale>$Language</UserLocale>"
@ -1208,7 +1262,6 @@ if ($WindowsProductName) {
$key = $ProductInfo['gvlk'] $key = $ProductInfo['gvlk']
Add-Content -Path $UnattendPath -Value ' <ProductKey>' Add-Content -Path $UnattendPath -Value ' <ProductKey>'
Add-Content -Path $UnattendPath -Value " <Key>$key</Key>" Add-Content -Path $UnattendPath -Value " <Key>$key</Key>"
Add-Content -Path $UnattendPath -Value ' <WillShowUI>Never</WillShowUI>'
Add-Content -Path $UnattendPath -Value ' </ProductKey>' Add-Content -Path $UnattendPath -Value ' </ProductKey>'
} }
Add-Content -Path $UnattendPath -Value ' </UserData>' Add-Content -Path $UnattendPath -Value ' </UserData>'
@ -1265,8 +1318,12 @@ elseif (!$NotFormat) {
Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ''
Add-Content -Path $UnattendPath -Value ' <ModifyPartitions>' Add-Content -Path $UnattendPath -Value ' <ModifyPartitions>'
Add-Content -Path $UnattendPath -Value ' <ModifyPartition wcm:action="add">' Add-Content -Path $UnattendPath -Value ' <ModifyPartition wcm:action="add">'
if ($PartitionStyle -ieq 'MBR') {
Add-Content -Path $UnattendPath -Value ' <Active>true</Active>'
}
Add-Content -Path $UnattendPath -Value ' <Format>NTFS</Format>' Add-Content -Path $UnattendPath -Value ' <Format>NTFS</Format>'
Add-Content -Path $UnattendPath -Value " <PartitionID>$PartitionID</PartitionID>" Add-Content -Path $UnattendPath -Value ' <Order>1</Order>'
Add-Content -Path $UnattendPath -Value " <PartitionID>$PartitionId</PartitionID>"
Add-Content -Path $UnattendPath -Value ' </ModifyPartition>' Add-Content -Path $UnattendPath -Value ' </ModifyPartition>'
Add-Content -Path $UnattendPath -Value ' </ModifyPartitions>' Add-Content -Path $UnattendPath -Value ' </ModifyPartitions>'
Add-Content -Path $UnattendPath -Value ' </Disk>' Add-Content -Path $UnattendPath -Value ' </Disk>'
@ -1276,12 +1333,7 @@ elseif (!$NotFormat) {
Add-Content -Path $UnattendPath -Value ' <ImageInstall>' Add-Content -Path $UnattendPath -Value ' <ImageInstall>'
Add-Content -Path $UnattendPath -Value ' <OSImage>' Add-Content -Path $UnattendPath -Value ' <OSImage>'
if ($WindowsProductName) { if ($WindowsProductName) {
if ($Language -ieq 'zh-CN') { $ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['US']
$ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['CN']
}
else {
$ImageName = 'Windows ' + $OsVersion + ' ' + $ProductInfo['US']
}
Add-Content -Path $UnattendPath -Value ' <InstallFrom>' Add-Content -Path $UnattendPath -Value ' <InstallFrom>'
Add-Content -Path $UnattendPath -Value ' <MetaData wcm:action="add">' Add-Content -Path $UnattendPath -Value ' <MetaData wcm:action="add">'
Add-Content -Path $UnattendPath -Value ' <Key>/IMAGE/NAME</Key>' Add-Content -Path $UnattendPath -Value ' <Key>/IMAGE/NAME</Key>'
@ -1293,7 +1345,7 @@ if ($WindowsProductName) {
Add-Content -Path $UnattendPath -Value ' <InstallTo>' Add-Content -Path $UnattendPath -Value ' <InstallTo>'
Add-Content -Path $UnattendPath -Value " <DiskID>$DiskId</DiskID>" Add-Content -Path $UnattendPath -Value " <DiskID>$DiskId</DiskID>"
Add-Content -Path $UnattendPath -Value " <PartitionID>$PartitionID</PartitionID>" Add-Content -Path $UnattendPath -Value " <PartitionID>$PartitionId</PartitionID>"
Add-Content -Path $UnattendPath -Value ' </InstallTo>' Add-Content -Path $UnattendPath -Value ' </InstallTo>'
Add-Content -Path $UnattendPath -Value ' </OSImage>' Add-Content -Path $UnattendPath -Value ' </OSImage>'
Add-Content -Path $UnattendPath -Value ' </ImageInstall>' Add-Content -Path $UnattendPath -Value ' </ImageInstall>'
@ -1301,23 +1353,6 @@ Add-Content -Path $UnattendPath -Value ' </component>'
Add-Content -Path $UnattendPath -Value ' </settings>' Add-Content -Path $UnattendPath -Value ' </settings>'
Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ''
Add-Content -Path $UnattendPath -Value ' <settings pass="specialize">' Add-Content -Path $UnattendPath -Value ' <settings pass="specialize">'
Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-International-Core`"" `
+ " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" `
+ " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" `
+ " xmlns:xsi=`"http://www.w3.org/2001/XMLSchema-instance`">")
if ('zh-CN' -eq $Language) {
Add-Content -Path $UnattendPath -Value (' <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}' + `
'{FA550B04-5AD7-411f-A5AC-CA038EC515D7}</InputLocale>')
}
else {
Add-Content -Path $UnattendPath -Value ' <InputLocale>0409:00000409</InputLocale>'
}
Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>"
Add-Content -Path $UnattendPath -Value " <SystemLocale>$Language</SystemLocale>"
Add-Content -Path $UnattendPath -Value " <UserLocale>$Language</UserLocale>"
Add-Content -Path $UnattendPath -Value " <UILanguageFallback>$Language</UILanguageFallback>"
Add-Content -Path $UnattendPath -Value ' </component>'
Add-Content -Path $UnattendPath -Value ''
Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-Security-SPP-UX`"" ` Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-Security-SPP-UX`"" `
+ " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" ` + " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" `
+ " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" ` + " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" `
@ -1344,6 +1379,17 @@ if ($WindowsProductName) {
Add-Content -Path $UnattendPath -Value ' </settings>' Add-Content -Path $UnattendPath -Value ' </settings>'
Add-Content -Path $UnattendPath -Value '' Add-Content -Path $UnattendPath -Value ''
Add-Content -Path $UnattendPath -Value ' <settings pass="oobeSystem">' Add-Content -Path $UnattendPath -Value ' <settings pass="oobeSystem">'
Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-International-Core`"" `
+ " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" `
+ " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" `
+ " xmlns:xsi=`"http://www.w3.org/2001/XMLSchema-instance`">")
Add-Content -Path $UnattendPath -Value " <InputLocale>$Language</InputLocale>"
Add-Content -Path $UnattendPath -Value " <UILanguage>$Language</UILanguage>"
Add-Content -Path $UnattendPath -Value " <SystemLocale>$Language</SystemLocale>"
Add-Content -Path $UnattendPath -Value " <UserLocale>$Language</UserLocale>"
Add-Content -Path $UnattendPath -Value " <UILanguageFallback>$Language</UILanguageFallback>"
Add-Content -Path $UnattendPath -Value ' </component>'
Add-Content -Path $UnattendPath -Value ''
Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-Shell-Setup`"" ` Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Windows-Shell-Setup`"" `
+ " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" ` + " processorArchitecture=`"$ArchitectureName`" publicKeyToken=`"$Token`" language=`"neutral`"" `
+ " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" ` + " versionScope=`"nonSxS`" xmlns:wcm=`"http://schemas.microsoft.com/WMIConfig/2002/State`"" `
@ -1383,13 +1429,6 @@ Add-Content -Path $UnattendPath -Value ' <HideWirelessSetupInOOBE
Add-Content -Path $UnattendPath -Value ' <HideLocalAccountScreen>true</HideLocalAccountScreen>' Add-Content -Path $UnattendPath -Value ' <HideLocalAccountScreen>true</HideLocalAccountScreen>'
Add-Content -Path $UnattendPath -Value ' <ProtectYourPC>3</ProtectYourPC>' Add-Content -Path $UnattendPath -Value ' <ProtectYourPC>3</ProtectYourPC>'
Add-Content -Path $UnattendPath -Value ' </OOBE>' 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 ' </component>'
Add-Content -Path $UnattendPath -Value ' </settings>' Add-Content -Path $UnattendPath -Value ' </settings>'
Add-Content -Path $UnattendPath -Value '</unattend>' Add-Content -Path $UnattendPath -Value '</unattend>'
@ -1397,3 +1436,4 @@ Add-Content -Path $UnattendPath -Value '</unattend>'
Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath) Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath)
Write-Host -Object '' Write-Host -Object ''
Read-Host -Prompt '按回车键关闭此窗口' Read-Host -Prompt '按回车键关闭此窗口'

2
product.json

@ -1,6 +1,6 @@
{ {
"name": "UnattendTool", "name": "UnattendTool",
"version": "2022.6.27", "version": "2022.6.30",
"files": [ "files": [
"UnattendTool.cmd", "UnattendTool.cmd",
"UnattendTool.ps1", "UnattendTool.ps1",

Loading…
Cancel
Save