cschneegans / unattend-generator

.NET Core library to create highly customized autounattend.xml files
https://schneegans.de/windows/unattend-generator/
MIT License
680 stars 62 forks source link

[FeatureRequest] Custom Hostname on Startup #45

Closed ychauhan100 closed 2 months ago

ychauhan100 commented 2 months ago

Is it possible to Prompt for Hostname at the time of Windows Setup. I have to configure 350 Windows machines and need custom names for all and not random/Desktop-UHVUHV.

cschneegans commented 2 months ago

I have tried that in the past. It sounds simple enough, but I have not managed to make it work during Windows Setup, despite trying several approaches:

• During the PE phase, mount the registry of the target installation and set the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName value. (This is similar to how disable-defender.vbs disables Windows Defender services before Windows boots for the first time.)

• During the Specialize phase, run PowerShell's Rename-Computer cmdlet as a custom script.

Unfortunately, Windows always sets a random computer name or, if present, the name given in the <ComputerName> element.

You should be able to call Rename-Computer when you add a custom PowerShell script in the Scripts to run when the first user logs on after Windows has been installed section, like so:

Rename-Computer -NewName ( Read-Host -Prompt 'New computer name' )

Of course, the new name takes effect only after a reboot.

ychauhan100 commented 2 months ago

For me the workaround was

Scripts to run when the first user logs on after Windows has been installed

1. Run as .ps1

Define domain details and credentials

$domainName = "Domain.com" $domainUsername = "DomainAdmin" $domainPassword = "Password" $securePassword = ConvertTo-SecureString $domainPassword -AsPlainText -Force $UserCredential = New-Object System.Management.Automation.PSCredential($domainUsername, $securePassword) Add-Computer -DomainName $DomainName -Credential $UserCredential -ErrorAction Stop

  1. Run as .ps1 $domainName = "Domain.com" $domainUsername = "DomainAdmin" $domainPassword = "Password" $securePassword = ConvertTo-SecureString $domainPassword -AsPlainText -Force $UserCredential = New-Object System.Management.Automation.PSCredential($domainUsername, $securePassword) Rename-Computer -NewName ( Read-Host -Prompt 'New computer name' ) -Domaincredential $UserCredential

:)

cschneegans commented 1 month ago

Just added a new setting Provide a PowerShell script to set the computer name dynamically, which you may find interesting:

image