Data acquiring script

Home Forums Scripting General Scripting Data acquiring script

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    sorinso
    Member
    #128431

    Hey, guys and girls.

    I wrote a script to harvest some hardware info from my computers all around the place (some 250 stations).
    I would like to hear your input on it:




    On Error Resume Next

    Const FOR_READING = 1
    Const FOR_WRITING = 2
    Const FOR_APPENDING = 8

    Const HARD_DISK = 3

    strComputer = “.”
    dataArr =””
    delim = “,”

    ‘ Computer name and model
    set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”)
    For Each objItem In colItems
    dataArr = dataArr & objItem.Name & delim & objItem.Model & delim
    ‘ objFile.Write objItem.Name & “,”
    ‘ objFile.Write objItem.Model & “,”
    Next

    ‘ Processor
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colCSItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”)
    Set colProcessors = objWMIService.ExecQuery(“Select * from Win32_Processor”)
    For Each objProcessor in colProcessors
    ‘ objFile.Write objProcessor.Name & “,”
    dataArr = dataArr & objProcessor.Name & delim
    Next

    ‘ Memory
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colOSItems = objWMIService.ExecQuery(“SELECT * FROM Win32_OperatingSystem”)
    For Each objOSItem In colOSItems
    ‘ objFile.Write Round((objOSItem.FreePhysicalMemory / 1024), 2) & “,”
    ‘ objFile.Write Round((objOSItem.TotalVisibleMemorySize / 1024), 2) & “,”
    dataArr = dataArr & Round((objOSItem.FreePhysicalMemory / 1024), 2) & delim &_
    Round((objOSItem.TotalVisibleMemorySize / 1024), 2) & delim
    Next

    ‘ Disks
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)

    Set colDisks = objWMIService.ExecQuery _
    (“Select * from Win32_LogicalDisk Where DriveType = ” & HARD_DISK & “”)

    For Each objDisk in colDisks
    ‘ objFile.Write “[” & objDisk.DeviceID & “]” & ” – ” & Round((objDisk.FreeSpace / (1024*1024)),0) & ” ”
    dataArr = dataArr & “[” & objDisk.DeviceID & “]” & ” – ” & Round((objDisk.FreeSpace / (1024*1024)),0) & delim
    Next
    ‘objFile.Write “,”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile _
    (“\[server][share]compdata.csv”, FOR_APPENDING, True)

    objFile.Write vbCrLf & dataArr

    objFile.Close
    [/CODE]

    TIA.[CODE]’



    On Error Resume Next

    Const FOR_READING = 1
    Const FOR_WRITING = 2
    Const FOR_APPENDING = 8

    Const HARD_DISK = 3

    strComputer = “.”
    dataArr =””
    delim = “,”

    ‘ Computer name and model
    set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”)
    For Each objItem In colItems
    dataArr = dataArr & objItem.Name & delim & objItem.Model & delim
    ‘ objFile.Write objItem.Name & “,”
    ‘ objFile.Write objItem.Model & “,”
    Next

    ‘ Processor
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colCSItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”)
    Set colProcessors = objWMIService.ExecQuery(“Select * from Win32_Processor”)
    For Each objProcessor in colProcessors
    ‘ objFile.Write objProcessor.Name & “,”
    dataArr = dataArr & objProcessor.Name & delim
    Next

    ‘ Memory
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colOSItems = objWMIService.ExecQuery(“SELECT * FROM Win32_OperatingSystem”)
    For Each objOSItem In colOSItems
    ‘ objFile.Write Round((objOSItem.FreePhysicalMemory / 1024), 2) & “,”
    ‘ objFile.Write Round((objOSItem.TotalVisibleMemorySize / 1024), 2) & “,”
    dataArr = dataArr & Round((objOSItem.FreePhysicalMemory / 1024), 2) & delim &_
    Round((objOSItem.TotalVisibleMemorySize / 1024), 2) & delim
    Next

    ‘ Disks
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)

    Set colDisks = objWMIService.ExecQuery _
    (“Select * from Win32_LogicalDisk Where DriveType = ” & HARD_DISK & “”)

    For Each objDisk in colDisks
    ‘ objFile.Write “[” & objDisk.DeviceID & “]” & ” – ” & Round((objDisk.FreeSpace / (1024*1024)),0) & ” “
    dataArr = dataArr & “[” & objDisk.DeviceID & “]” & ” – ” & Round((objDisk.FreeSpace / (1024*1024)),0) & delim
    Next
    ‘objFile.Write “,”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile _
    (“\[server][share]compdata.csv”, FOR_APPENDING, True)

    objFile.Write vbCrLf & dataArr

    objFile.Close
    [/CODE]

    TIA.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.