Browse Source

支持设置登录账户密码

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

2
README.md

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

33
UnattendTool.ps1

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
$PartitionId = -1,
$PartitionStyle = 'GPT',
$FullName = 'MyPC',
$Password = '',
$VentoyDriverLetter = '',
$ISOPath = '',
[switch]$Interactive,
@ -785,6 +786,24 @@ function ShowNameInput { @@ -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) { @@ -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 (" <component name=`"Microsoft-Win @@ -1397,7 +1417,12 @@ Add-Content -Path $UnattendPath -Value (" <component name=`"Microsoft-Win
if ($FullName) {
Add-Content -Path $UnattendPath -Value ' <AutoLogon>'
Add-Content -Path $UnattendPath -Value ' <Password>'
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 ' <Enabled>true</Enabled>'
@ -1408,7 +1433,12 @@ if ($FullName) { @@ -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>'
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>' @@ -1443,5 +1473,6 @@ Add-Content -Path $UnattendPath -Value '</unattend>'
Write-Host -Object ('生成的应答文件位置: ' + $UnattendPath)
Write-Host -Object ''
if ($Interactive) {
Read-Host -Prompt '按回车键关闭此窗口'
}

Loading…
Cancel
Save