PowerShell Rename-Computer issue — names with underscores


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

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.


PowerShell Rename-Computer issue — names with underscores by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply