From 0606a1278c1876eec2dad6fbea6f64a7229a71c9 Mon Sep 17 00:00:00 2001 From: JonasKloseBW Date: Thu, 27 Feb 2025 18:37:29 +0100 Subject: [PATCH] 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 --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 99b701a..0d7b7b7 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -222,6 +222,7 @@ if (Test-Path -Path $PPKGFolder){ $UnattendFolder = $USBDrive + "unattend\" $UnattendFilePath = $UnattendFolder + "unattend.xml" $UnattendPrefixPath = $UnattendFolder + "prefixes.txt" +$UnattendComputerNamePath = $UnattendFolder + "SerialComputerNames.csv" If (Test-Path -Path $UnattendFilePath){ $UnattendFile = Get-ChildItem -Path $UnattendFilePath If ($UnattendFile){ @@ -234,6 +235,12 @@ If (Test-Path -Path $UnattendPrefixPath){ $UnattendPrefix = $true } } +If (Test-Path -Path $UnattendComputerNamePath){ + $UnattendComputerNameFile = Get-ChildItem -Path $UnattendComputerNamePath + If ($UnattendComputerNameFile){ + $UnattendComputerName = $true + } +} #Ask for device name if unattend exists if ($Unattend -and $UnattendPrefix){ @@ -278,7 +285,25 @@ if ($Unattend -and $UnattendPrefix){ $computername = Set-Computername($computername) Writelog "Computer name set to $computername" } -elseif($Unattend){ +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) { Writelog 'Unattend file found with no prefixes.txt, asking for name' [string]$computername = Read-Host 'Enter device name' Set-Computername($computername)