I'm writing a PowerShell script using Rename-Computer, and I'm hitting an odd issue:
PS C:\Users\Administrator> Rename-Computer -NewName 395_s2
Rename-Computer : Skip computer 'ztest' with new name '395_s2' because the new name is not valid. The new computer name entered is not properly formatted. Standard names may contain letters (a-z, A-Z), numbers (0-9), and hyphens (-), but no spaces or periods (.). The name may not consist entirely of digits, and may not be longer than 63 characters.
I would really prefer to be able to use underscores in the machine names, and the -Force flag doesn't change the output.
When I enter the same name manually in Computer->System Properties->Computer Name/Domain Changes, it asks:
Do you want to use this computer name?
The name "395_s2" contains non-standard characters. This might cause problems with some applications or network hardware.
I have the option to choose yes and override the non-standard characters. Is there a way to do this directly in PowerShell?
Using WMI doesnt seem to have that limitation. I just tested it on my own computer
(Get-WmiObject Win32_ComputerSystem).Rename("te_st")
It's not Rename-Computer but it looks like it works. Also going to repost my comment on Mad's post. There is a really good post about computer names and underscores. The use of the underscore in host names
To quote one of the answers as well as agreeing with Mad Scientist
Though its valid to use underscores it not a recommended practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With