Closed zehadialam closed 3 weeks ago
Hi Zehadi, I had a similar issue but to solve it Simply I made the prefix 1 character shorter or removed the dash "-" to come in under the 15 character limit.
May I ask why you want to have Device Names longer then 15 Characters? I know there are issues with AD and NetBIOS if you go longer. I believe Entra Joined devices doesn't care so much but local AD does.
You could try to trim the computer names from the beginning of the serial Number instead.
$serial = (Get-CimInstance -ClassName win32_bios).SerialNumber.Trim().Substring((Get-CimInstance -ClassName win32_bios).SerialNumber.Trim().Length - 7, 7)
This might work a little for you a little longer but at some point you may run into the same issue with the leading character being dropped when you get batch of devices from the same production run.
-Scott
Hello Scott. Thank you for your input, however it seems that the most reliable option would be to retain the full computer name. We don't add any devices to an on-prem AD.
I'm not too crazy about setting the name via the registry like that. It wouldn't be a supported method to do it that way. Are you doing it this way to prevent a reboot?
You may want to try using the unattend to run a synchronous command to call Rename-Computer via PowerShell.
Thanks, that way seems a lot better. I hadn't realized that Rename-Computer
accepts names longer than 15 characters.
I've done something similar using the Unattend.xml when I was trying to apply a provisioning package that was loaded at Apps Install Phase.
<SynchronousCommand wcm:action="add">
<CommandLine>powershell.exe -ExecutionPolicy Bypass -File C:\Provisioning\ApplyProvisioningPackage.ps1</CommandLine>
<Description>Apply Provisioning Package</Description>
<Order>1</Order>
</SynchronousCommand>
I am also thinking , couldn't you just simply remove the Trim of 15 IF Statement?
`$computername = ($PrefixToUse + $serial) -replace "\s","" # Remove spaces because windows does not support spaces in the computer names
$computername = Set-Computername($computername)
should allow you to have your prefix and keep all the characters of the Serial Number, without the need for RunCommands or registry hacks.
You can't just remove the trim. Unattend doesn't like having names longer than 15 characters. Check the comment you quoted :)
You can't just remove the trim. Unattend doesn't like having names longer than 15 characters. Check the comment you quoted :)
.. you are correct sir! I forgot the 15 Character limit is still applied in Unattend.xml . Its been a week..lol
@zehadialam You can also put your code right in the XML.
I use this site for help creating parts of the unattend scripts: https://schneegans.de/windows/unattend-generator/#:~:text=Windows%C2%A011%2023H2.-,Run%20custom%20scripts%3A,-Scripts%20to%20run
Hi Richard,
I've been working on a solution to set computer names longer than 15 characters. We recently encountered an issue where our new lab devices ended up with identical names, as the serial numbers only differed by the last character, which was truncated.
My current implementation involves letting the
unattend.xml
do the initial naming and then change the name using aSetupComplete.cmd
script.Let me know if you'd be interested in a PR for this solution, or if you have alternative suggestions.
Thank you, Zehadi