脚本-收集计算机信息

闲来无事,想把公司域内的计算机统计一些乱七八糟的信息出来.但是我比较懒,没有把我公司环境的内容修改成大家都可以用的,仅仅放在这里给大家一个思路.我对代码确实是不太懂的,做的东西也都是东拼西凑只为满足需求就可以,代码漂亮度就不纠结了.

说明一下,上面的是BAT批处理,下面的是VBS脚本.因为从WMI拿数据我不知道怎么在批处理里面做.在批处理前面一段是用来拿批处理能拿到的信息,中间调用了VBS来拿WMI里面的数据.然后在批处理结尾把导出的TXT文本调整一下.

注意:这只是我随手的分享我自己的环境下能用的东西,其他地方并不一定能用,只是给大家一个思路.请有一定代码能力的人修改后再用到自己的环境.我并不对这段代码负责.

另外有写批处理,VBS或POWERSHELL厉害的能教教我吗...


以下是批处理

@echo off
echo 请输入保存位置
set /p oppath=
set t=%time: =0%
echo ====================================================>"%oppath%\%computername%-%username%.txt"
echo 计算机相关信息>>"%oppath%\%computername%-%username%.txt"
echo.>>"%oppath%\%computername%-%username%.txt"
echo 最后一次登陆时间:            %date:~,4%年%date:~5,2%月%date:~8,2%日 %t:~0,2%时%t:~3,2%分%t:~6,2%秒>>"%oppath%\%computername%-%username%.txt"
echo 计算机名:                    %computername%>>"%oppath%\%computername%-%username%.txt"
net config workstation | find "计算机全名" >>"%oppath%\%computername%-%username%.txt"
echo 当前登录的计算机名:          %computername%>>"%oppath%\%computername%-%username%.txt"
echo 当前登录的用户名:            %username%>>"%oppath%\%computername%-%username%.txt"
echo ====================================================>>"%oppath%\%computername%-%username%.txt"
echo IP地址相关信息>>"%oppath%\%computername%-%username%.txt"
echo.>>"%oppath%\%computername%-%username%.txt"
@echo off>>"%oppath%\%computername%-%username%.txt"
ipconfig |find "IPv4">>"%oppath%\%computername%-%username%.txt"
@echo off>>"%oppath%\%computername%-%username%.txt"
ipconfig |find "网关">>"%oppath%\%computername%-%username%.txt"
@echo off>>"%oppath%\%computername%-%username%.txt"
ipconfig/all |find "DNS 服务器">>"%oppath%\%computername%-%username%.txt"
@echo off>>"%oppath%\%computername%-%username%.txt"
ipconfig/all |find "DHCP 服务器">>"%oppath%\%computername%-%username%.txt"
echo ====================================================>>"%oppath%\%computername%-%username%.txt"
echo off
cscript %oppath%\script\Get_Information.vbs>>"%oppath%\%computername%-%username%.txt"
set Keyword1=Microsoft (R) Windows Script Host Version 5.8
set Keyword2=版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
findstr /v /c:"%Keyword1%" %oppath%\%computername%-%username%.txt>%oppath%\%computername%-%username%.temp
move /y %oppath%\%computername%-%username%.temp %oppath%\%computername%-%username%.txt
findstr /v /c:"%Keyword2%" %oppath%\%computername%-%username%.txt>%oppath%\%computername%-%username%.temp
move /y %oppath%\%computername%-%username%.temp %oppath%\%computername%-%username%.txt
systeminfo >>"%oppath%\%computername%-%username%.txt"
pause


以下是VBS

        Wscript.Echo "计算机硬件信息"
        Wscript.Echo 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_BIOS",,48) 
    Wscript.Echo "*计算机品牌"  
For Each objItem in colItems 
    Wscript.Echo objItem.Manufacturer
Wscript.Echo "--------------------------"
Wscript.Echo 
    Wscript.Echo "*序列号"  
    Wscript.Echo objItem.SerialNumber
Next
        Wscript.Echo "--------------------------"
Wscript.Echo 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
    Wscript.Echo "*计算机类型"  
For Each objChassis in colChassis
    For  Each strChassisType in objChassis.ChassisTypes
        Select Case strChassisType
            Case 1
                Wscript.Echo "Other"
            Case 2
                Wscript.Echo "Unknown"
            Case 3
                Wscript.Echo "Desktop"
            Case 4
                Wscript.Echo "Low Profile Desktop"
            Case 5
                Wscript.Echo "Pizza Box"
            Case 6
                Wscript.Echo "Mini Tower"
            Case 7
                Wscript.Echo "Tower"
            Case 8
                Wscript.Echo "Portable"
            Case 9
                Wscript.Echo "Laptop"
            Case 10
                Wscript.Echo "Notebook"
            Case 11
                Wscript.Echo "Handheld"
            Case 12
                Wscript.Echo "Docking Station"
            Case 13
                Wscript.Echo "All-in-One"
            Case 14
                Wscript.Echo "Sub-Notebook"
            Case 15
                Wscript.Echo "Space Saving"
            Case 16
                Wscript.Echo "Lunch Box"
            Case 17
                Wscript.Echo "Main System Chassis"
            Case 18
                Wscript.Echo "Expansion Chassis"
            Case 19
                Wscript.Echo "Sub-Chassis"
            Case 20
                Wscript.Echo "Bus Expansion Chassis"
            Case 21
                Wscript.Echo "Peripheral Chassis"
            Case 22
                Wscript.Echo "Storage Chassis"
            Case 23
                Wscript.Echo "Rack Mount Chassis"
            Case 24
                Wscript.Echo "Sealed-Case PC"
            Case Else
                Wscript.Echo "Unknown"
            End Select
    Next
Next
        Wscript.Echo "--------------------------"
nicnum=1
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Processor",,48) 
For Each objItem in colItems 
    Wscript.Echo 
    Wscript.Echo "*CPU型号"
    Wscript.Echo objItem.Name
Next
        Wscript.Echo "--------------------------"

On Error Resume Next 
dim Memory
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colItems = objWMIService.ExecQuery _ 
    ("Select * from Win32_PhysicalMemory") 
 
For Each objItem in colItems 

   Memory =  objItem.Capacity/1024/1024/1024
    Wscript.Echo 
    Wscript.Echo "*内存容量"  
    Wscript.Echo("Memory=" & Memory & "G")

Next 
    Wscript.Echo "--------------------------"
    Wscript.Echo 

Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 
For Each objItem in colItems 
    If isNull(objItem.IPAddress) Then
        'Wscript.Echo "IPAddress: "
    Else
        Wscript.Echo "*网卡"&nicnum
	Wscript.Echo "网卡名称:" &objItem.caption
        Wscript.Echo "IPV4:" & Join(objItem.IPAddress,chr(10)&"IPV6:")
	Wscript.Echo "MAC地址:" &objItem.macAddress&chr(10)
nicnum=nicnum+1
    End If
Next
        Wscript.Echo "--------------------------"


你可能感兴趣的:(bat,vbs)