Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Discrepancy in Computer Name

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
US
I am writing a script such that, it will display computer name based on IP address

Code:
Set objWMISvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", ,48 )
For Each objItem in colItems
     strComputerDomain = objItem.Domain
   Next

However, when I do

ping -a IP Address

on the same command prompt where I executed this script, I get an entirely different computer name.


I notice this for several computers.


What is the most reliable way to display the computer name, based on IP address.

NOTE: We use dynamic DHCP servers that renews IP addresses ever few days, but this comparison was done within minutes.
 
I'd use DNSHostName instead of Domain ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I made mistake in my code. It is:

Code:
Set objWMISvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", ,48 )

For Each objItem in colItems     
strName = objItem.Caption 

Next


I was copying and pasting parts of the code.


But, on a side note, I will try

Code:
strComputerDomain = objItem.DNSHostName

for a separate issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top