Reputation: 61
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?
Upvotes: 5
Views: 4923
Reputation: 46710
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.
Upvotes: 4
Reputation: 36297
As an answer I am not going to show you how to get it to rename your computer with underscores, instead I will strongly suggest that you do not use them in your computer names.
I would like to refer you to RFC 1178, which is designed solely with the purpose of helping people make good decisions when naming their computers. You can find it at:
https://www.rfc-editor.org/rfc/rfc1178
As to why you shouldn't, there are a number of applications and systems that will not work if your hostname has an underscore in it, including things as standard as Internet Explorer.
Plus systems such as DomainKeys and service records use the underscore as a means to assure that their special character is not confused with hostnames (ref: Wikipedia).
Upvotes: 0