Closed ychauhan100 closed 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.
For me the workaround was
$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
:)
Just added a new setting Provide a PowerShell script to set the computer name dynamically, which you may find interesting:
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.