编写vbs脚本获取Windows server的系统信息

因为公司最近让我写脚本来监控Windows Server的使用情况,考虑了好久决定使用vbs和bat结合来完成对Windows Server服务器资源的监控。

               下面是vbs脚本:

 

REM ‘获取IP地址’
REM ‘判断DNS是否为空,判断IP地址开头是否为10或192’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE”,,48)
For Each objItem in colItems
If isNULL(objItem.DNSServerSearchOrder) Then
Else
IPX=objItem.IPAddress(0)
LefIP=split(IPX,”.”)(0)
If LefIP=”10″ OR LefIP=”192″ Then
IP=IPX
Wscript.Echo “ip:” & IP
End If
End If
Next

REM ‘获取SN号’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_BIOS”,,48)
For Each objItem in colItems
SN=objItem.SerialNumber
Wscript.Echo “Sn: ” & SN
Next

REM ‘获取CPU信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_Processor”,,48)
For Each objItem in colItems
Processor=objItem.Name
Wscript.Echo “Processors: ” & Processor
Next

REM ‘获取内存信息’
Set wmiService = GetObject(“winmgmts:\\.\root\cimv2”)
Set wmiObjects = wmiService.ExecQuery(“SELECT * FROM CIM_OperatingSystem”)
For Each wmiObject In wmiObjects
all=round(wmiObject.TotalVisibleMemorySize/1024/1024)
over=round(wmiObject.FreePhysicalMemory/1024/1024)
Wscript.Echo “TotalMemory: ” & all & “G”
Wscript.Echo “FreeMemory: ” & over & “G”
Next

REM ‘获取硬盘信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_DiskDrive”,,48)
For Each objItem in colItems
Disk=Disk& objItem.Model & ” (” & round(objItem.Size/1073741824) & “G) , ”
Wscript.Echo “Disk: ” & Disk

Set objWMIService = GetObject(“winmgmts:”)

Set objLogicalDisk = objWMIService.Get(“Win32_LogicalDisk.DeviceID=’c:‘”)

Wscript.Echo “C盘可用容量: “&cint(objLogicalDisk.FreeSpace / 1024 / 1024 / 1024) & “GB”

Next

REM ‘获取电脑品牌’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_BaseBoard”,,48)
For Each objItem in colItems
Pinpai=objItem.Manufacturer
Next

REM ‘获取Summary信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_BaseBoard”,,48)
For Each objItem in colItems
Product=objItem.Product
Summary=Pinpai & ” ” & Product & “,” & Processor & “,” & Memory
Wscript.Echo “Summary: ” & Summary
Next

REM ‘获取Chipset信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_Processor”,,48)
For Each objItem in colItems
Chipset=objItem.Caption
Wscript.Echo “Chipset: ” & Chipset
Next

REM ‘获取系统类型’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_OperatingSystem”,,48)
For Each objItem in colItems
OS=objItem.Caption
Wscript.Echo “OS: ” & OS
Next

REM ‘获取BIOS信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_BIOS”,,48)
For Each objItem in colItems
If isNull(objItem.BIOSVersion) Then
Wscript.Echo “BIOS: ”
Else
BIOS=Join(objItem.BIOSVersion,”,”)
Wscript.Echo “BIOS: ” & BIOS
End If
Next

REM ‘获取计算机名’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_ComputerSystem”,,48)
For Each objItem in colItems
Hostname=objItem.DNSHostName
Wscript.Echo “Hostname:” & Hostname
Next

REM ‘获取MAC地址’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”,,48)
For Each objItem in colItems
Macaddress=objItem.MACAddress
Wscript.Echo “MACAddress: ” & Macaddress
Next

REM ‘获取Network信息’
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”,,48)
For Each objItem in colItems
Network=Mid(objItem.Caption,InStr(objItem.Caption,”]”)+1) & ” ” & Macaddress
Wscript.Echo “Network: ” & Network
Next

REM ‘curl发包’
Dim Info
Info=”Summary: ” & Summary & Chr(13) & “Processors: ” & Processor & Chr(13) & “Memory: ” & Memory & Chr(13) & “Disk: ” & Disk & Chr(13) & “Chipset: ” & Chipset & Chr(13) & “Network: ” & Network & Chr(13) & “BIOS: ” & BIOS

dim curlcmd
dim cmdstr
set curlcmd=Createobject(“wscript.shell”)
cmdstr = “curl.exe -d “”ip=” & IP & “&sn=” & SN & “&info=” & Info & “”” https://ams.nxadmin.com/api/hwinfo”
curlcmd.run cmdstr

                bat脚本:

@echo off
echo “正在获取操作系统信息……”
echo 计算机信息: >info.txt
cscript //Nologo Get_Machine.vbs >> info.txt

编写vbs脚本获取Windows server的系统信息

上一篇:Win10系统的备份与还原


下一篇:CENTOS中cat命令中文乱码 VIM乱码设置