Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


windows:ad:upd_cmp_desc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
windows:ad:upd_cmp_desc [2019/10/31 09:06]
127.0.0.1 external edit
windows:ad:upd_cmp_desc [2020/02/06 12:59]
tplecko
Line 17: Line 17:
 Set WshNetwork = WScript.CreateObject("​WScript.Network"​) Set WshNetwork = WScript.CreateObject("​WScript.Network"​)
 Set objWMI = GetObject("​winmgmts:​{impersonationLevel=impersonate}!\\.\root\cimv2"​) Set objWMI = GetObject("​winmgmts:​{impersonationLevel=impersonate}!\\.\root\cimv2"​)
 + 
 ' Get service tag and computer manufacturer ' Get service tag and computer manufacturer
 For Each objSMBIOS in objWMI.ExecQuery("​Select * from Win32_SystemEnclosure"​) For Each objSMBIOS in objWMI.ExecQuery("​Select * from Win32_SystemEnclosure"​)
Line 23: Line 23:
   manufacturer = replace(objSMBIOS.Manufacturer,​ ",",​ "​."​)   manufacturer = replace(objSMBIOS.Manufacturer,​ ",",​ "​."​)
 Next Next
 + 
 ' Get computer model ' Get computer model
 For Each objComputer in objWMI.ExecQuery("​Select * from Win32_ComputerSystem"​) For Each objComputer in objWMI.ExecQuery("​Select * from Win32_ComputerSystem"​)
   model = trim(replace(objComputer.Model,​ ",",​ "​."​))   model = trim(replace(objComputer.Model,​ ",",​ "​."​))
 Next Next
 + 
 ' Get computer object in AD ' Get computer object in AD
 Set objSysInfo = CreateObject("​ADSystemInfo"​) Set objSysInfo = CreateObject("​ADSystemInfo"​)
 Set objComputer = GetObject("​LDAP://"​ & objSysInfo.ComputerName) Set objComputer = GetObject("​LDAP://"​ & objSysInfo.ComputerName)
 + 
 ' Get user object in AD ' Get user object in AD
 Set objUser = GetObject("​LDAP://"​ & objSysInfo.UserName) Set objUser = GetObject("​LDAP://"​ & objSysInfo.UserName)
 + 
 +' Get all IP addresses
 +Dim NIC1, Nic, StrIP
 +StrIP=""​
 +Set NIC1 =     ​GetObject("​winmgmts:"​).InstancesOf("​Win32_NetworkAdapterConfiguration"​)
 +
 +For Each Nic in NIC1
 +    if Nic.IPEnabled then
 + For Each ip in Nic.IPAddress
 + If Len(StrIP)=0 then
 + StrIP = ip
 + Else
 + StrIP = StrIP & ", " & ip
 + End if
 + Next
 +    End if
 +Next
  
 ' Build up description field data and save into computer object if different from current description ' Build up description field data and save into computer object if different from current description
-newDescription = objUser.LastName & " " & objUser.FirstName & " (" & WshNetwork.UserName & ") - " & manufacturer & " " & model & " (" & serviceTag & "​)"​ +newDescription = objUser.LastName & " " & objUser.FirstName & " (" & WshNetwork.UserName & ") - " & manufacturer & " " & model & " (" & serviceTag & "​) ​[" & StrIP & "]
 + 
 ' We also do not update computers with a description that starts with an underscore (_) ' We also do not update computers with a description that starts with an underscore (_)
 if not objComputer.Description = newDescription and not left(objComputer.Description,​1) = "​_" ​ then if not objComputer.Description = newDescription and not left(objComputer.Description,​1) = "​_" ​ then
Line 45: Line 62:
 end if end if
 '​WScript.StdOut.WriteLine newDescription '​WScript.StdOut.WriteLine newDescription
- 
 </​code>​ </​code>​
  
windows/ad/upd_cmp_desc.txt · Last modified: 2020/02/06 12:59 by tplecko