Скрипт инвентаризации компьютеров под Windows

Den1xxx

Разрушитель (V)
Сообщения
126
Симпатии
69
Баллы
1 016
Писал сам, когда работал на заводе, может кому пригодится
Файл создайте — hardware.vbs, код внутри:
Код:
strComputer = "."
rem strPath is path to server folder
strPath = "\\MyServer\Share\Inventory\"
line = vbCrLf & "----------------------------------------" & vbCrLf

report = "Date = " & Now() & line

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

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

title = " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

For Each objOperatingSystem in colSettings
    report = report & "Software" & line
    report = report & "OS Name = " & objOperatingSystem.Name & vbCrLf
    report = report & "Version = " & objOperatingSystem.Version & vbCrLf
    report = report & "Service Pack = " & _
        objOperatingSystem.ServicePackMajorVersion _
            & "." & objOperatingSystem.ServicePackMinorVersion & vbCrLf
    report = report & "OS Manufacturer = " & objOperatingSystem.Manufacturer & vbCrLf
    report = report & "Windows Directory = " & _
        objOperatingSystem.WindowsDirectory & vbCrLf
    'report = report & "Locale: " & objOperatingSystem.Locale & vbCrLf
    report = report & "Available Physical Memory = " & _
        objOperatingSystem.FreePhysicalMemory & vbCrLf
    report = report & "Total Virtual Memory =" & _
        objOperatingSystem.TotalVirtualMemorySize & vbCrLf
    report = report & "Available Virtual Memory = " & _
        objOperatingSystem.FreeVirtualMemory & vbCrLf
    report = report & "Size stored in paging files = " & _
        objOperatingSystem.SizeStoredInPagingFiles & vbCrLf
Next

    report = report & vbCrLf

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")

    report = report & "Hardware" & line
For Each objComputer in colSettings
    compname = objComputer.Name
    report = report & "System Name = " & objComputer.Name & vbCrLf
    report = report & "System Manufacturer = " & objComputer.Manufacturer & vbCrLf
    report = report & "System Model = " & objComputer.Model & vbCrLf
    report = report & "Time Zone = " & objComputer.CurrentTimeZone & vbCrLf
    report = report & "Total Physical Memory = " & _
        objComputer.TotalPhysicalMemory & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_Processor")

For Each objProcessor in colSettings
    report = report & "System Type = " & objProcessor.Architecture & vbCrLf
    report = report & "Processor = " & objProcessor.Description & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")

For Each objBIOS in colSettings
    report = report & "BIOS Version = " & objBIOS.Version & vbCrLf
Next
   
   
    DT = Now
    DateVal = Year(DT) & _
              Right("0" & Month(DT), 2) & _
              Right("0" & Day(DT), 2) & _
              Right("0" & Hour(DT), 2) & _
              Right("0" & Minute(DT), 2) & _
              Right("0" & Second(DT), 2)

dim strNameSpace, objWMIService, colItems, BoardInfo, objItem, objClassProperty

strNameSpace = "\root\cimv2"
' Windows Management Instrumentation
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"  & strComputer & strNameSpace)
Set colItems = objWMIService.ExecQuery ("Select Name,Manufacturer,Product,Version,SerialNumber from Win32_Baseboard")



For Each objItem in colItems
    For Each objClassProperty In objItem.Properties_
        if (objClassProperty.Name="ConfigOptions") then
            BoardInfo = BoardInfo & objClassProperty.Name & " = " & join(objClassProperty.value) & vbCrLf
        else
            If Len(objClassProperty.value)>0 Then
                BoardInfo = BoardInfo & objClassProperty.Name & " = " & objClassProperty.value & vbCrLf
            End If
        end if
    Next
Next

report = report & BoardInfo & vbCrLf

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2")

Set HostNameSet = objWMIService.ExecQuery("select DNSHostName from Win32_NetworkAdapterConfiguration where ipenabled = true")
Set MACAddress = objWMIService.ExecQuery("select MACAddress from Win32_NetworkAdapterConfiguration where ipenabled = true")
Set IPConfigSet = objWMIService.ExecQuery("select IPAddress from Win32_NetworkAdapterConfiguration where ipenabled = true")

Text = VbCrLf

For Each obj in HostNameSet
    Text = "Name = " & obj.DNSHostName & VbCrLf
Next


'Text = Text & VbCrLf

For Each oAdptr in MACAddress
    Text = Text & "MAC = " & oAdptr.MACAddress & VbCrLf
Next

'Text = Text & VbCrLf


for each IPConfig in IPConfigSet
    if Not IsNull(IPConfig.IPAddress) then
        for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
            Text = Text & "IP = " &IPConfig.IPAddress(i)& VbCrLf
        next
    end if
next
report = report & "Network configuration" & line

report = report & Text & vbCrLf

    FileName = strPath & compname & "_" & DateVal & ".txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.CreateTextFile (FileName, ForWriting)
ts.write report
WScript.Echo report

Как пользоваться
1. Создать папку на сервере MS — \\MyServer\Share\Inventory\ (MyServer замените на свое в скрипте и в жизни)
2. В \\MyServer\Share\ положить скрипт права чтение всем, в \\MyServer\Share\Inventory\ сделать скрытой, права всем запись.
3. С каждого компа зайти на \\MyServer\Share\hardware.vbs
Пользователю отразится инфа о его компе, а в папке Inventory сохранятся единообразные логи. Которые можно прочитать глазами или парсить скриптом.

В чем преимущество перед готовым софтом?
Это бесплатно и можно дописать под нужды, притом основная инфа есть (модель материнки, название компа, память, процессоры, сетевухи и тп).
 
Назад
Верх