dsccommunity / ComputerManagementDsc

DSC resources for for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.
https://dsccommunity.org
MIT License
300 stars 83 forks source link

Computer names longer than 15 are blocked, but the limit is 63 #379

Open markleavesley opened 2 years ago

markleavesley commented 2 years ago

Details of the scenario you tried and the problem that is occurring

Renaming a PC with a name that is more than 15 characters will fail. However if you rename the same PC through right-click Start, System, "Rename this PC" you can use up to 63 characters (I understand the 15 character limit comes from NetBIOS).

Verbose logs showing the problem

PowerShell DSC resource DSC_Computer failed to execute Test-TargetResource functionality with error message: Cannot validate argument on parameter 'Name'. The character length of the 16 argument is too long. Shorten the character length of the argument so it is fewer than or equal to "15" characters, and then try the command again.

Suggested solution to the issue

To avoid breaking existing behaviour, add a new property that supports the 63 character limit.

The DSC configuration that is used to reproduce the issue (as detailed as possible)


Computer RenamePC
{
    Name = "1234567890123456"
}

The operating system the target node is running

OsName : Microsoft Windows Server 2019 Datacenter OsOperatingSystemSKU : DatacenterServerEdition OsArchitecture : 64-bit WindowsVersion : 1809 WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.17763.2183 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.2183 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

Latest as installed by PS (8.5.0)

PlagueHO commented 2 years ago

Hi @markleavesley - this is a interesting issue (which is why I've labelled it with discussion). At first glance this seemed simple enough, but it actually a little more complex:

The challenge here is that the Name parameter does just test and set the NetBios name of the machine. What I believe you're wanting to do is set the hostname. Using a single parameter to represent two differing values (Hostname and NetBios name) will result in config flapping, so we can't just use the Name parameter to represent the Hostname - or if we did, we'd need to replicate the logic that Rename-Computer uses to truncate the hostname to the netbios name.

One solution to this would be to add completely new parameters for setting the hostname. This does get more complex because Rename-Computer (which this resource uses) cmdlet sets both the hostname and the NetBios name.

I think all this is possible, but it would need a bit of discussion to select the right approach.

markleavesley commented 2 years ago

@PlagueHO Thanks for the prompt reply. I was using Rename-Computer before as it happens.

For context, I am deploying VM scale sets using a specialized image and whilst renaming them to their portal names using PS works, it needs a reboot and the recommended solution I keep seeing is to rename using DSC and let it handle the reboot, hence I am here.

PlagueHO commented 2 years ago

Hi @markleavesley - sorry for not returning to this yet. I'm still thinking we may need to think about this a little bit more as we may need a breaking change to get this to work as the behavior of Rename-Computer might require a different method of changing the computer name and hostname if we want to allow them to differ.