System Administration Scripting

2007年5月18日星期五

域中电脑软硬件基本信息统计

strDomainName = InputBox ("Please enter the internal Domain Name:","Script 

for auditting machines on Domain","Sitename.local")
arrDomLevels = Split(strDomainName, ".")
strADsPath = "dc=" & Join(arrDomLevels, ",dc=")


Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"'

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://"&strADsPath&"' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set of = oFSO.CreateTextFile("E:\DomainPCs.txt", True, True)

Do Until objRecordSet.EOF
On Error Resume Next
sPC = objRecordSet.Fields("Name").Value
of.writeline " "
of.writeline "### "&sPC&" ###"
of.writeline " "


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

If Err = 0 Then


Set col = objWMILocator.ExecQuery _
("Select * from win32_computersystem")

For Each item In col
of.writeline "General Info"
of.writeline " Name: "&item.Caption
of.writeline " Username: "&item.username
of.writeline " Domain: "&item.Domain
of.writeline " Role: "&fDomainRole(item.domainrole)
of.writeline " Manufacturer: "&fCheckValue

(item.manufacturer, Empty, Empty)
of.writeline " Model: "&fCheckValue(item.model, Empty,

Empty)
of.writeline " Type: "&item.systemtype
of.writeline " Processors: "&item.numberofprocessors
of.writeline " Memory: "&fFormatNum

(item.totalphysicalmemory,True)
Next
Set col = Nothing
Set objWMIInstance = objWMILocator.ExecQuery _
("select * from win32_operatingsystem",,48)
For Each item In objWMIInstance
If InStr(1, item.Caption, "2000") Then
strOS = "2000"

Elseif InStr(1, item.caption, "XP") Then
strOS = "XP"

Elseif InStr(1, item.caption, "2003") Then
strOS = "2003"

Else
strOS = "WinNT9x"

End If

If strOS = "2003" Then
of.writeline " OS: "&Replace(item.Caption,

"Microsoft(R) Windows(R)", "")
Else
of.writeline " OS: "&Replace(item.Caption,

"Microsoft Windows", "")
End If
of.writeline " Version: "&item.Version
of.writeline " SP: "&item.csdversion
of.writeline " OS Lang: "&fLangVers(Hex

(item.oslanguage))
of.writeline " Serial #: "&item.serialnumber
Next
Set objWMIInstance = Nothing

of.writeline " "
of.writeline "System Info"
Set objWMIInstance = objWMILocator.ExecQuery _
("select * from win32_BIOS",,48)

For Each item In objWMIInstance
of.writeline " BIOS Name: "&item.Name
of.writeline " BIOS Version: "&item.SMBIOSBIOSVersion
of.writeline " Serial #: "&item.SerialNumber
Next
Set objWMIInstance = Nothing

Set objWMIInstance = objWMILocator.ExecQuery _
("select buildversion from win32_wmisetting",,48)
For Each item In objWMIInstance
of.writeline " WMI Version: "&item.buildversion
Next
Set objWMIInstance = Nothing



Set objWMIInstance = objWMILocator.ExecQuery _
("select tag, description, devicetype, enabled from

win32_onboarddevice")

i = 0
For Each item In objWMIInstance
i =i + 1
Next

of.writeline " Onboard Devices: "&i
For Each item In objWMIInstance
of.writeline " Description: "&item.description
of.writeline " Enabled: "&item.enabled
Next
Set objWMIInstance = Nothing

of.writeline " "
of.writeline "Processor Infomation"
Set objWMIInstance = objWMILocator.ExecQuery _
("select * from win32_processor")
of.writeline " Total processor slots: "&objWMIInstance.Count
For Each item In objWMIInstance
If item.ProcessorID <>"0000000000000000" Then
of.writeline " "

of.writeline " Processor ID: "&item.deviceID
of.writeline " Name: "&item.Name

of.writeline " Type: "&item.Description

of.writeline " Family: "&fProcFamily(item.family)

of.writeline " Speed: "&item.currentclockspeed & "

Mhz"
of.writeline " Cache Size: "&fCheckValue

(item.l2cachesize, Empty, " Kb")
of.writeline " Cache Speed: "&fCheckValue

(item.l2cachespeed, Empty, " Mhz")
of.writeline " External Clock: "&fCheckValue

(item.extClock, Empty, " Mhz")
of.writeline " Interface: "&fProcUpgrademethod

(item.upgrademethod)
of.writeline " CPU Load: "&fCheckValue

(item.loadpercentage, Empty, "%")
'of.writeline item.processorid
End If
Next
Set objWMIInstance = Nothing
of.writeline " "
of.writeline "Memory Infomation"

Set objWMIInstance = objWMILocator.ExecQuery _
("Select memorydevices from Win32_PhysicalMemoryArray",,48)
marry = 0
For Each item In objWMIInstance
marry = marry + item.memorydevices
Next
of.writeline " Total Memory Slots: "&marry
Set objWMIInstance = Nothing
query = "select capacity, formfactor, memorytype, banklabel,

devicelocator " _
& "from win32_physicalmemory"
Set objWMIInstance = objWMILocator.ExecQuery(query)
a = objWMIInstance.Count
of.writeline " Used memory slots: "&a
bcounter =0
For Each item In objWMIInstance

of.writeline " "

If item.BankLabel="" Then
b = item.DeviceLocator
Else
b = item.BankLabel
End If

of.writeline " Bank Name: "&b
of.writeline " Memory Size: "&fFormatNum

(item.Capacity, True)
of.writeline " Memory Form: "&fMemoryForm

(item.FormFactor)
of.writeline " Memory Tpye: "&fMemoryType

(item.MemoryType)

Next
Set objWMIInstance = Nothing
of.writeline " "
of.writeline "Disk Info"
Set objWMIInstance = objWMILocator.ExecQuery _
("select manufacturer, description, caption, interfacetype,

partitions, size, scsibus, scsitargetid, status from win32_diskdrive")
ttlDisks = objWMIInstance.Count
of.writeline " Total Disks: "&ttlDisks

For Each item In objWMIInstance
of.writeline " "

If strOS = "2000" Then
strDiskDescription = item.Caption
Elseif strOS = "2003" Then
strDiskDescription = item.Caption
Elseif strOS = "XP" Then
strDiskDescription = item.Caption
Else
strDiskDescription = item.manufacturer & " " &

item.Description
End If

of.writeline " "&(Replace(item.deviceID, "\\.\", "")

& " - " & strDiskDescription) & " - " & item.interfacetype
of.writeline " Status: "&item.Status
of.writeline " Partitions: "&item.partitions
of.writeline " Type: "&item.interfacetype
of.writeline " Size: "&fFormatNum(item.Size,

False)
If item.interfacetype = "IDE" Then
of.writeline " IDE Bus#:

"&item.scsibus
of.writeline " IDE ID: "&item.scsitargetid
Else
of.writeline " SCSI Bus#:

"&item.scsibus
of.writeline " SCSI ID:

"&item.scsitargetid
End If

Set objPartitionSet = item.Associators_

("Win32_DiskDriveToDiskPartition", "Win32_DiskPartition")
For Each objPartition In objPartitionSet
Set objDriveSet = objPartition.Associators_

("Win32_LogicalDiskToPartition", "Win32_LogicalDisk")

For Each objDrive In objDriveSet
If objPartition.bootpartition Then
of.writeline " Drive:

"&objDrive.Caption & " - Boot Partition"
Else
of.writeline " Drive:

"&objDrive.Caption
End If
of.writeline " Label:

"&objDrive.VolumeName
of.writeline " File Sys:

"&objDrive.FileSystem
of.writeline " Size: "&fFormatNum

(objDrive.Size, False)
of.writeline " Free: "&fFormatNum

(objDrive.FreeSpace, False)
of.writeline " S/N: "&

fCheckValue(objDrive.VolumeSerialNumber, Empty, Empty)


Next
Next

Next
Set objWMIInstance = Nothing

of.writeline " "
of.writeline "Other Info"
Set objWMIInstance = objWMILocator.ExecQuery _
("select * from Win32_CDROMDrive")
of.writeline " "

of.writeline " Total CDROM Drives: "&objWMIInstance.Count
For Each item In objWMIInstance
of.writeline " Name: "&item.Caption
of.writeline " Drive: "&item.id
Next
Set objWMIInstance = Nothing
Set objWMIInstance = objWMILocator.ExecQuery _
("select * from Win32_FloppyDrive")
of.writeline " "

of.writeline " Total FloppyDrives: "&objWMIInstance.Count
For Each item In objWMIInstance
of.writeline " Name: "&item.Caption
' of.writeline " Drive: "&item.DeviceID
Next
Set objWMIInstance = Nothing
of.writeline " "



Set objWMIInstance = objWMILocator.ExecQuery _
("select * from Win32_TapeDrive")

of.writeline " Tape Drives: "&objWMIInstance.Count
For Each item In objWMIInstance
of.writeline " Name: "&item.Caption
' of.writeline " Drive: "&item.id
Next
Set objWMIInstance = Nothing
of.writeline " "

Set objWMIInstance = objWMILocator.ExecQuery _
("select * from Win32_Keyboard")
For Each item In objWMIInstance
of.writeline " Keyboard Type: "&item.Caption

Next
Set objWMIInstance = Nothing
of.writeline " "



Set objWMIInstance = objWMILocator.ExecQuery _
("select * from Win32_DesktopMonitor")

For Each item In objWMIInstance
of.writeline " Monitor Type: "&item.Caption

Next
Set objWMIInstance = Nothing
of.writeline " "

Set objWMIInstance = objWMILocator.ExecQuery _
("select * from win32_networkadapterconfiguration WHERE

IPEnabled='TRUE' AND ServiceName<>'AsyncMac' AND ServiceName<>'VMnetx' " _
& "AND ServiceName<>'VMnetadapter' AND ServiceName<>'Rasl2tp'

AND ServiceName<>'PptpMiniport' AND ServiceName<>'Raspti' " _
& "AND ServiceName<>'NDISWan' AND ServiceName<>'RasPppoe' AND

ServiceName<>'NdisIP' AND ServiceName<>''")

of.writeline " Network Adapters: "&objWMIInstance.Count

For Each item In objWMIInstance
If UCase(item.ipenabled)="TRUE" Then
blnIPState = "(Enabled)"
Else
blnIPState = "(Disabled)"
End If
of.writeline " Adapter Name: "&fCheckValue

(item.Description & " - " & blnIPState, Empty, Empty)

Next
Set objWMIInstance = Nothing
of.writeline " "






End If

objRecordSet.MoveNext
Loop


Function fMemoryType(value)
Dim dictMemType
Set dictMemType = CreateObject("scripting.dictionary")
dictMemType.Add "0","Unknown"
dictMemType.Add "1","Other"
dictMemType.Add "2","DRAM"
dictMemType.Add "3","Synchronous DRAM"
dictMemType.Add "4","Cache DRAM"
dictMemType.Add "5","EDO"
dictMemType.Add "6","EDRAM"
dictMemType.Add "7","VRAM"
dictMemType.Add "8","SRAM"
dictMemType.Add "9","RAM"
dictMemType.Add "10","ROM"
dictMemType.Add "11","Flash"
dictMemType.Add "12","EEPROM"
dictMemType.Add "13","FEPROM"
dictMemType.Add "14","EPROM"
dictMemType.Add "15","CDRAM"
dictMemType.Add "16","3DRAM"
dictMemType.Add "17","SDRAM"
dictMemType.Add "18","SGRAM"
dictMemType.Add "19","RDRAM"
dictMemType.Add "20","DDR"
fMemoryType = dictMemType.Item(CStr(value))
Set dictMemType = Nothing
End Function



Function fMemoryForm(value)
Dim dictMemForm
Set dictMemForm = CreateObject("scripting.dictionary")
dictMemForm.Add "0","Unknown"
dictMemForm.Add "1","Other"
dictMemForm.Add "2","SIP"
dictMemForm.Add "3","DIP"
dictMemForm.Add "4","ZIP"
dictMemForm.Add "5","SOJ"
dictMemForm.Add "6","Proprietary"
dictMemForm.Add "7","SIMM"
dictMemForm.Add "8","DIMM"
dictMemForm.Add "9","TSOP"
dictMemForm.Add "10","PAG"
dictMemForm.Add "11","RIMM"
dictMemForm.Add "12","SODIMM"
dictMemForm.Add "13","SRIMM"
dictMemForm.Add "14","SMD"
dictMemForm.Add "15","SSMP"
dictMemForm.Add "16","QFD"
dictMemForm.Add "17","TQFP"
dictMemForm.Add "18","SOIC"
dictMemForm.Add "19","LCC"
dictMemForm.Add "20","PLCC"
dictMemForm.Add "21","BGA"
dictMemForm.Add "22","FPBGA"
dictMemForm.Add "23","LGA"
fMemoryForm = dictMemForm.Item(CStr(value))
Set dictMemForm = Nothing
End Function

Function fProcUpgradeMethod(value)
Dim dictInterface
Set dictInterface = CreateObject("scripting.dictionary")
dictInterface.Add "1","Other"
dictInterface.Add "2","Unknown"
dictInterface.Add "3","Daughter Board"
dictInterface.Add "4","ZIF Socket"
dictInterface.Add "5","Replacement/Piggy Back"
dictInterface.Add "6","None"
dictInterface.Add "7","LIF Socket"
dictInterface.Add "8","Slot 1"
dictInterface.Add "9","Slot 2"
dictInterface.Add "10","370 Pin Socket"
dictInterface.Add "11","Slot A"
dictInterface.Add "12","Slot M"
fProcUpgradeMethod = dictInterface.Item(CStr(value))
Set dictInterface = Nothing
End Function


Function fProcFamily(value)
Dim dictProc
Set dictProc = CreateObject("scripting.dictionary")
dictProc.Add "1", "Other"
dictProc.Add "2", "Unknown"
dictProc.Add "3", "8086"
dictProc.Add "4", "80286"
dictProc.Add "5", "80386"
dictProc.Add "6", "80486"
dictProc.Add "7", "8087"
dictProc.Add "8", "80287"
dictProc.Add "9", "80387"
dictProc.Add "10", "80487"
dictProc.Add "11", "Pentium brand"
dictProc.Add "12", "Pentium Pro"
dictProc.Add "13", "Pentium II"
dictProc.Add "14", "Pentium processor with MMX technology"
dictProc.Add "15", "Celeron"
dictProc.Add "16", "Pentium II Xeon"
dictProc.Add "17", "Pentium III"
dictProc.Add "18", "M1 Family"
dictProc.Add "19", "M2 Family"
dictProc.Add "24", "K5 Family"
dictProc.Add "25", "K6 Family"
dictProc.Add "26", "K6-2"
dictProc.Add "27", "K6-3"
dictProc.Add "28", "AMD Athlon Processor Family"
dictProc.Add "29", "AMD Duron Processor"
dictProc.Add "30", "AMD2900 Family"
dictProc.Add "31", "K6-2+"
dictProc.Add "32", "Power PC Family"
dictProc.Add "33", "Power PC 601"
dictProc.Add "34", "Power PC 603"
dictProc.Add "35", "Power PC 603+"
dictProc.Add "36", "Power PC 604"
dictProc.Add "37", "Power PC 620"
dictProc.Add "38", "Power PC X704"
dictProc.Add "39", "Power PC 750"
dictProc.Add "48", "Alpha Family"
dictProc.Add "49", "Alpha 21064"
dictProc.Add "50", "Alpha 21066"
dictProc.Add "51", "Alpha 21164"
dictProc.Add "52", "Alpha 21164PC"
dictProc.Add "53", "Alpha 21164a"
dictProc.Add "54", "Alpha 21264"
dictProc.Add "55", "Alpha 21364"
dictProc.Add "64", "MIPS Family"
dictProc.Add "65", "MIPS R4000"
dictProc.Add "66", "MIPS R4200"
dictProc.Add "67", "MIPS R4400"
dictProc.Add "68", "MIPS R4600"
dictProc.Add "69", "MIPS R10000"
dictProc.Add "80", "SPARC Family"
dictProc.Add "81", "SuperSPARC"
dictProc.Add "82", "microSPARC II"
dictProc.Add "83", "microSPARC IIep"
dictProc.Add "84", "UltraSPARC"
dictProc.Add "85", "UltraSPARC II"
dictProc.Add "86", "UltraSPARC IIi"
dictProc.Add "87", "UltraSPARC III"
dictProc.Add "88", "UltraSPARC IIIi"
dictProc.Add "96", "68040"
dictProc.Add "97", "68xxx Family"
dictProc.Add "98", "68000"
dictProc.Add "99", "68010"
dictProc.Add "100", "68020"
dictProc.Add "101", "68030"
dictProc.Add "112", "Hobbit Family"
dictProc.Add "120", "Crusoe TM5000 Family"
dictProc.Add "121", "Crusoe TM3000 Family"
dictProc.Add "128", "Weitek"
dictProc.Add "130", "Itanium Processor"
dictProc.Add "144", "PA-RISC Family"
dictProc.Add "145", "PA-RISC 8500"
dictProc.Add "146", "PA-RISC 8000"
dictProc.Add "147", "PA-RISC 7300LC"
dictProc.Add "148", "PA-RISC 7200"
dictProc.Add "149", "PA-RISC 7100LC"
dictProc.Add "150", "PA-RISC 7100"
dictProc.Add "160", "V30 Family"
dictProc.Add "176", "Pentium III Xeon"
dictProc.Add "177", "Pentium III Processor with Intel SpeedStep

Technology"
dictProc.Add "178", "Pentium 4"
dictProc.Add "179", "Intel Xeon"
dictProc.Add "180", "AS400 Family"
dictProc.Add "181", "Intel Xeon processor MP"
dictProc.Add "182", "AMD AthlonXP Family"
dictProc.Add "183", "AMD AthlonMP Family"
dictProc.Add "184", "Intel Itanium 2"
dictProc.Add "185", "AMD Opteron Family"
dictProc.Add "190", "K7"
dictProc.Add "200", "IBM390 Family"
dictProc.Add "201", "G4"
dictProc.Add "202", "G5"
dictProc.Add "250", "i860"
dictProc.Add "251", "i960"
dictProc.Add "260", "SH-3"
dictProc.Add "261", "SH-4"
dictProc.Add "280", "ARM"
dictProc.Add "281", "StrongARM"
dictProc.Add "300", "6x86"
dictProc.Add "301", "MediaGX"
dictProc.Add "302", "MII"
dictProc.Add "320", "WinChip"
dictProc.Add "350", "DSP"
dictProc.Add "500", "Video Processor"

fProcFamily = dictProc.Item(CStr(value))
Set dictProc = Nothing
End Function


Function fLangVers(value)
Dim dictLang
Set dictLang = CreateObject("scripting.dictionary")
dictLang.Add "409","English (US)"
dictLang.add "809","English (Britain)"
dictLang.Add "1009","English (Canada)I"
dictLang.Add "1409","English (New Zealand)"
dictLang.Add "0c09","English (Australian)"
dictLang.Add "1809","English (Ireland)"
dictLang.Add "1c09","English (South America)"
dictLang.Add "2009","English (Jamaica)"
dictLang.Add "2409","English (Caribbean)"
dictLang.Add "40c","French (Standard)"
dictLang.Add "80c","French (Belgian)"
dictLang.Add "100c","French (Switzerland)"
dictLang.Add "c0c","French (Canadian)"
dictLang.Add "140c","French (Luxembourg)"
dictLang.Add "407","German (Standard)"
dictLang.Add "807","German (Switzerland)"
dictLang.Add "c07","German (Austria)"
dictLang.Add "1007","German (Luxembourg)"
dictLang.Add "1407","German (Liechtenstein)"
dictLang.Add "411","Japanese"
dictLang.Add "80a","Spanish (Mexican)"
dictLang.Add "40a","Spanish (Traditinal Sort)"
dictLang.Add "c0a","Spanish (Modern Sort)"
fLangVers = dictLang.item(Lcase(CStr(value)))
Set dictLang = Nothing
End Function

Function fDomainRole(value)
Dim dictDomRole
Set dictDomRole = CreateObject("scripting.dictionary")
dictDomRole.Add "0","Standalone Workstation"
dictDomRole.Add "1","Member Workstation"
dictDomRole.Add "2","Standalone Server"
dictDomRole.Add "3","Member Server"
dictDomRole.Add "4","Backup Domain Controller"
dictDomRole.Add "5","Primary Domain Controller"
fDomainRole = dictDomRole.Item(CStr(value))
Set dictDomRole = Nothing
End Function

Function fCheckValue(varValue, prepender, appender)
If IsNull(varValue) Or varValue = "" Then
fCheckValue = "N/A"
Else
fCheckValue = CStr(prepender & varValue & appender)
End If
End Function

Private Function fFormatNum(num, DropDecimal)
Dim bytes
Dim lngSize
If IsNumeric(num) Then
If Len(num) < 5 Then
lngSize = FormatNumber((num /1024), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Gb"
Elseif Len(num) < 7 Then
lngSize = FormatNumber((num / 1024), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Kb"
Elseif Len(num) < 10 Then
lngSize = FormatNumber((num / 1024 ^ 2), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Mb"
Elseif Len(num) < 13 Then
lngSize = FormatNumber((num / 1024 ^ 3), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Gb"
Elseif Len(num) < 16 Then
lngSize = FormatNumber((num / 1024 ^ 4), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Tb"
Elseif Len(num) >= 16 Then
lngSize = FormatNumber((num / 1024 ^ 5), 2, vbTrue,

vbTrue, vbUseDefault)
bytes = " Pb"
End If
If DropDecimal Or Right(lngSize, 2) = "00" Then
fFormatNum = CStr(Round(lngSize, 0)) & bytes
Else
fFormatNum = CStr(lngSize) & bytes
End If
Else
fFormatNum = num
End If
End Function

of.close
MsgBox "Done!"

Bookmark this post:
Ma.gnolia DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google


0 评论:

相关文章

©2007