Browse Source

支持设置登录账户密码

main
dsx42 3 years ago
parent
commit
d6882981b3
  1. 2
      README.md
  2. 39
      UnattendTool.ps1

2
README.md

@ -64,6 +64,7 @@
[-PartitionID int] [-PartitionID int]
[-PartitionStyle String] [-PartitionStyle String]
[-FullName String] [-FullName String]
[-Password String]
[-VentoyDriverLetter String] [-VentoyDriverLetter String]
[-ISOPath String] [-ISOPath String]
[-NotFormat] [-NotFormat]
@ -93,6 +94,7 @@
* `GPT`:GPT 分区;默认值 * `GPT`:GPT 分区;默认值
* `MBR`:MBR 分区 * `MBR`:MBR 分区
* `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'` * `-FullName String`:系统安装后的登录账号名;推荐英文字母或数字的组合,尽量不使用中文或其他特殊字符;默认为 `'MyPC'`
* `-Password String`:系统安装后的登录账号密码;推荐不设置密码,系统安装后再自行设置密码;默认无密码
* `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面 * `-VentoyDriverLetter String`:已安装 Ventoy 的 U 盘驱动器;默认为当前用户的桌面
* `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定 * `-ISOPath String`:使用应答文件的 ISO 镜像文件的路径;默认未指定
* `-NotFormat`:安装系统时不格式化所选硬盘分区;默认安装时会格式化所选硬盘分区 * `-NotFormat`:安装系统时不格式化所选硬盘分区;默认安装时会格式化所选硬盘分区

39
UnattendTool.ps1

@ -7,6 +7,7 @@
$PartitionId = -1, $PartitionId = -1,
$PartitionStyle = 'GPT', $PartitionStyle = 'GPT',
$FullName = 'MyPC', $FullName = 'MyPC',
$Password = '',
$VentoyDriverLetter = '', $VentoyDriverLetter = '',
$ISOPath = '', $ISOPath = '',
[switch]$Interactive, [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 { function ShowVentoyDriverLetterSelect {
$CurrentDisks = GetCurrentDisk $CurrentDisks = GetCurrentDisk
@ -1111,6 +1130,7 @@ if ($Interactive) {
} }
} }
$FullName = ShowNameInput $FullName = ShowNameInput
$Password = ShowPasswordInput
$VentoyDriverLetter = ShowVentoyDriverLetterSelect $VentoyDriverLetter = ShowVentoyDriverLetterSelect
if ($VentoyDriverLetter) { if ($VentoyDriverLetter) {
$ISOPath = ShowGetISOPath -Path $VentoyDriverLetter $ISOPath = ShowGetISOPath -Path $VentoyDriverLetter
@ -1397,7 +1417,12 @@ Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Win
if ($FullName) { if ($FullName) {
Add-Content -Path $UnattendPath -Value ' <AutoLogon>' Add-Content -Path $UnattendPath -Value ' <AutoLogon>'
Add-Content -Path $UnattendPath -Value ' <Password>' 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 ' <PlainText>true</PlainText>'
Add-Content -Path $UnattendPath -Value ' </Password>' Add-Content -Path $UnattendPath -Value ' </Password>'
Add-Content -Path $UnattendPath -Value ' <Enabled>true</Enabled>' 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 ' <LocalAccounts>'
Add-Content -Path $UnattendPath -Value ' <LocalAccount wcm:action="add">' Add-Content -Path $UnattendPath -Value ' <LocalAccount wcm:action="add">'
Add-Content -Path $UnattendPath -Value ' <Password>' 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 ' <PlainText>true</PlainText>'
Add-Content -Path $UnattendPath -Value ' </Password>' Add-Content -Path $UnattendPath -Value ' </Password>'
Add-Content -Path $UnattendPath -Value " <DisplayName>$FullName</DisplayName>" 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 ('生成的应答文件位置: ' + $UnattendPath)
Write-Host -Object '' Write-Host -Object ''
Read-Host -Prompt '按回车键关闭此窗口' if ($Interactive) {
Read-Host -Prompt '按回车键关闭此窗口'
}

Loading…
Cancel
Save