mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Update ApplyFFU.ps1
- Allows setting the computer name with a predefined list (SerialComputerNames.csv) of serial numbers and matching computer names
- Defaults to FFU-{Random} if no matching serial number is found in list so FFU deployment can continue without user input
This commit is contained in:
@@ -222,6 +222,7 @@ if (Test-Path -Path $PPKGFolder){
|
|||||||
$UnattendFolder = $USBDrive + "unattend\"
|
$UnattendFolder = $USBDrive + "unattend\"
|
||||||
$UnattendFilePath = $UnattendFolder + "unattend.xml"
|
$UnattendFilePath = $UnattendFolder + "unattend.xml"
|
||||||
$UnattendPrefixPath = $UnattendFolder + "prefixes.txt"
|
$UnattendPrefixPath = $UnattendFolder + "prefixes.txt"
|
||||||
|
$UnattendComputerNamePath = $UnattendFolder + "SerialComputerNames.csv"
|
||||||
If (Test-Path -Path $UnattendFilePath){
|
If (Test-Path -Path $UnattendFilePath){
|
||||||
$UnattendFile = Get-ChildItem -Path $UnattendFilePath
|
$UnattendFile = Get-ChildItem -Path $UnattendFilePath
|
||||||
If ($UnattendFile){
|
If ($UnattendFile){
|
||||||
@@ -234,6 +235,12 @@ If (Test-Path -Path $UnattendPrefixPath){
|
|||||||
$UnattendPrefix = $true
|
$UnattendPrefix = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
If (Test-Path -Path $UnattendComputerNamePath){
|
||||||
|
$UnattendComputerNameFile = Get-ChildItem -Path $UnattendComputerNamePath
|
||||||
|
If ($UnattendComputerNameFile){
|
||||||
|
$UnattendComputerName = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Ask for device name if unattend exists
|
#Ask for device name if unattend exists
|
||||||
if ($Unattend -and $UnattendPrefix){
|
if ($Unattend -and $UnattendPrefix){
|
||||||
@@ -278,6 +285,24 @@ if ($Unattend -and $UnattendPrefix){
|
|||||||
$computername = Set-Computername($computername)
|
$computername = Set-Computername($computername)
|
||||||
Writelog "Computer name set to $computername"
|
Writelog "Computer name set to $computername"
|
||||||
}
|
}
|
||||||
|
elseif($Unattend -and $UnattendComputerName){
|
||||||
|
Writelog 'Unattend file found with SerialComputerNames.csv. Getting name for current computer.'
|
||||||
|
$SerialComputerNames = Import-Csv -Path $UnattendComputerNameFile.FullName -Delimiter ","
|
||||||
|
|
||||||
|
$SerialNumber = (Get-CimInstance -Class Win32_Bios).SerialNumber
|
||||||
|
$SCName = $SerialComputerNames | Where-Object { $_.SerialNumber -eq $SerialNumber }
|
||||||
|
|
||||||
|
If ($SCName) {
|
||||||
|
[string]$computername = $SCName.ComputerName
|
||||||
|
$computername = Set-Computername($computername)
|
||||||
|
Writelog "Computer name set to $computername"
|
||||||
|
} else {
|
||||||
|
Writelog 'No matching serial number found in SerialComputerNames.csv. Setting random computer name to complete setup.'
|
||||||
|
[string]$computername = ("FFU-" + (-join ((48..57) + (65..90) + (97..122) | Get-Random -Count 11 | ForEach-Object { [char]$_ })))
|
||||||
|
$computername = Set-Computername($computername)
|
||||||
|
Writelog "Computer name set to $computername"
|
||||||
|
}
|
||||||
|
}
|
||||||
elseif($Unattend) {
|
elseif($Unattend) {
|
||||||
Writelog 'Unattend file found with no prefixes.txt, asking for name'
|
Writelog 'Unattend file found with no prefixes.txt, asking for name'
|
||||||
[string]$computername = Read-Host 'Enter device name'
|
[string]$computername = Read-Host 'Enter device name'
|
||||||
|
|||||||
Reference in New Issue
Block a user