0

These 2 properties appear to be set to the same values on a standard Windows domain environment. Can they be different? How can they be set to different values?

e.g.

$computer = Get-WMIObject Win32_ComputerSystem
$computer.Name
$computer.DNSHostName
SturmUndDrang
  • 1,876
  • 5
  • 27
  • 47

2 Answers2

0

They appear to be different properties, though presumably they will have the same value. Win32_ComputerSystem Doc

DNSHostName:

  • Data type: string
  • Access type: Read-only
  • Qualifiers: MappingStrings ("Win32API|GetComputerNameEx|ComputerNameDnsHostname")
  • Name of local computer according to the domain name server (DNS).

Name:

  • Data type: string
  • Access type: Read-only
  • Qualifiers: Key
  • Key of a CIM_System instance in an enterprise environment.
  • This property is inherited from CIM_ManagedSystemElement.

Document states both properties are read-only. Get-Member suggests they are set-able, but I'd be skeptical.

Steven
  • 6,817
  • 1
  • 14
  • 14
  • Thanks for the response. I am still unclear *when* they would be different values (e.g. when would the DNS server have a different name compared to Windows). I haven't encountered them being different on different systems/environments – SturmUndDrang Sep 11 '20 at 21:38
  • I wouldn't expect them to be different. Are you seeing a difference? Your question sounds like you want to assert a change/difference... – Steven Sep 11 '20 at 22:29
  • I have a legacy application that currently records and updates both. I'm wondering if I can safely remove one, I.e. What is the benefit of having both? In what circumstances can they be different? If I chose one over the other, which is best to use? – SturmUndDrang Sep 12 '20 at 06:07
  • Unfortunately I don't think we have the resources to confidently answer that. Not with certainty. It's likely that if you change the name the system will re-register with DNS. How exactly are you updating them if they are read-only? There is a rename method as well. – Steven Sep 12 '20 at 13:11
  • I'm sorry, I may not have been clear. I am reading these 2 properties and storing them. If a computer changes it's name I need to update these stored values (in a RDBMS). I'm asking the question because I want to know if both are needed or whether using just 1 will suffice. I do not know the history of why both were stored originally, I just want to know if it is possible that they can have different values (i.e. there is value in keeping both). – SturmUndDrang Sep 14 '20 at 07:53
  • I think there's sufficient justification to leave the current code & data alone. Continue storing both items. I can't rule out the DNS record being different or wrong. If the WMI class is truly resolving the name there are certainly cases where it could be. These days most systems are doing Dynamic DNS so it's probably transient and/or rare. If the code/DB/process is already accommodating that edge case, leave it alone and allow it to continue to do so... No one is going to nag you for accommodating an uncertainty. – Steven Sep 14 '20 at 12:51
0

One difference is that 'Name' is limited by 15 chars (it works like GetComputerName() win32 API), while 'DNSHostName' is not (it works like GetComputerNameEx(ComputerNameDnsHostname) win32 API).

So 'Name' will contain truncated Computer Name if its length > 15 chars; but 'DNSHostName' will contain full Computer Name