sebus

GetCustom

Jun 28th, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Dim objRootDSE, objNetwork, objWMIService, objComputer
  4. Dim strComputer, strModel
  5. Dim colModel, objModel
  6. Dim adoConnection, adoRecordset
  7.  
  8. strComputer = "."
  9. strModel = ""
  10.  
  11. Set objRootDSE = GetObject("LDAP://RootDSE")
  12. Set objNetwork = WScript.CreateObject("WScript.Network")
  13. Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2")
  14.  
  15. Set colModel = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
  16.  
  17. strModel = ""
  18.  
  19. If Not colModel Is Nothing Then
  20.     For Each objModel in colModel
  21.         If strModel <> "" Then
  22.             strModel = strModel & " "
  23.         End If
  24.         strModel = strModel & trim(replace(objModel.Model, ",", "."))
  25.     Next
  26. End If
  27.  
  28. Set adoConnection = CreateObject("ADODB.Connection")
  29. adoConnection.Provider = "ADsDSOObject"
  30. adoConnection.Open "Active Directory Provider"
  31.  
  32. If Err.Number <> 0 Then
  33.     WScript.Quit
  34. End If
  35.  
  36. Set adoRecordset = adoConnection.Execute("<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree")
  37.  
  38. If Err.Number <> 0 Then
  39.     WScript.Quit
  40. End If
  41.  
  42. If Not adoRecordset.EOF Then
  43.     Set objComputer = GetObject(adoRecordset.Fields(0).Value)
  44.     objComputer.Put "Custom-HardwareModel", strModel
  45.     objComputer.SetInfo
  46. End If
  47.  
  48. If Err.Number <> 0 Then
  49.     WScript.Quit
  50. End If
Advertisement
Add Comment
Please, Sign In to add comment