diff --git a/README.md b/README.md index f3dd5a9..5ba0264 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ [-PartitionID int] [-PartitionStyle String] [-FullName String] + [-Password String] [-VentoyDriverLetter String] [-ISOPath String] [-NotFormat] @@ -93,6 +94,7 @@ * `GPT`:GPT 分区;默认值 * `MBR`:MBR 分区 * `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'` +* `-Password String`:系统安装后的登录账号密码;推荐不设置密码,系统安装后再自行设置密码;默认无密码 * `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面 * `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定 * `-NotFormat`:安装系统时不格式化所选硬盘分区;默认安装时会格式化所选硬盘分区 diff --git a/UnattendTool.ps1 b/UnattendTool.ps1 index 37ee931..4bc8a7e 100644 --- a/UnattendTool.ps1 +++ b/UnattendTool.ps1 @@ -7,6 +7,7 @@ $PartitionId = -1, $PartitionStyle = 'GPT', $FullName = 'MyPC', + $Password = '', $VentoyDriverLetter = '', $ISOPath = '', [switch]$Interactive, @@ -785,6 +786,24 @@ function ShowNameInput { } } +function ShowPasswordInput { + + Write-Host -Object '======================================================================' + Write-Host -Object '输入系统安装后的登录账号密码,推荐不设置密码,系统安装后再自行设置密码' + Write-Host -Object '======================================================================' + Write-Host -Object '' + + $InputOption = Read-Host -Prompt '请输入登录账号密码(默认无密码),按回车键确认' + if ($InputOption -ieq '') { + Write-Host -Object '' + return '' + } + else { + Write-Host -Object '' + return $InputOption + } +} + function ShowVentoyDriverLetterSelect { $CurrentDisks = GetCurrentDisk @@ -1111,6 +1130,7 @@ if ($Interactive) { } } $FullName = ShowNameInput + $Password = ShowPasswordInput $VentoyDriverLetter = ShowVentoyDriverLetterSelect if ($VentoyDriverLetter) { $ISOPath = ShowGetISOPath -Path $VentoyDriverLetter @@ -1397,7 +1417,12 @@ Add-Content -Path $UnattendPath -Value (" ' Add-Content -Path $UnattendPath -Value ' ' - Add-Content -Path $UnattendPath -Value ' ' + if ($Password) { + Add-Content -Path $UnattendPath -Value " $Password" + } + else { + 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>' @@ -1408,7 +1433,12 @@ if ($FullName) { 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/>' + if ($Password) { + Add-Content -Path $UnattendPath -Value " <Value>$Password</Value>" + } + else { + 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>" @@ -1443,5 +1473,6 @@ Add-Content -Path $UnattendPath -Value '</unattend>' Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath) Write-Host -Object '' -Read-Host -Prompt '按回车键关闭此窗口' - +if ($Interactive) { + Read-Host -Prompt '按回车键关闭此窗口' +}