[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Audit script help

Posted on 2011-04-26
2
Medium Priority
?
407 Views
Last Modified: 2012-06-27
Hi all

Please help, I'm not a talented coder but have found a script to audit hardware. I'd like to use with an input file so it could be used for multiple remote machines and I could collate the results.

I've had a go but gotten no where fast.
'==========================================================================
'
' NAME: <MemProcDiskInventory.vbs>
'
' AUTHOR: Mark D. MacLachlan , ITSynergy
' DATE  : 5/15/2003
'
' COMMENT: <Inventories computer configuration and writes report to disk>
'==========================================================================
on error resume Next

Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")


report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
    report = report &  strComputer  & vbCrLf & "OS Details"& vbCrlf
    report = report &  "Caption: " & objItem.Caption & vbCrLf
    report = report &  "Description: " & objItem.Description & vbCrLf
    report = report &  "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
    report = report &  "InstallDate: " & objItem.InstallDate & vbCrLf
    report = report &  "Manufacturer: " & objItem.Manufacturer & vbCrLf
    report = report &  "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
    report = report &  "Name: " & objItem.Name & vbCrLf
    report = report &  "Organization: " & objItem.Organization & vbCrLf
    report = report &  "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
    report = report &  "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
    report = report &  "SerialNumber: " & objItem.SerialNumber & vbCrLf
    report = report &  "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion & vbCrLf
    report = report &  "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
    report = report &  "Version: " & objItem.Version & vbCrLf
    report = report &  "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings 
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_Processor")
For Each objProcessor in colSettings 
report = report & objProcessor.Description & " Processor" & vbCrLf
Next

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
report = report & objLogicalDisk.FreeSpace /1024\1024+1 & "MB Free Disk Space" & vbCrLf
report = report & objLogicalDisk.Size /1024\1024+1 & "MB Total Disk Space" & vbCrLf

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = vbCrLf & "******************************************" & vbCrLf
software = software & vbCrLf & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
    software = software & subkey & vbCrLf
End If
Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile (strComputer & ".txt", ForWriting)
ts.write report
ts.write software
'MsgBox Report
MsgBox "Done"

Open in new window

0
Comment
Question by:samymac
2 Comments
 
LVL 29

Accepted Solution

by:
mass2612 earned 2000 total points
ID: 35467309
Hi,

You could try this. I did not test this at all. You need a text file called "Computers.txt"with each system you want to check on a seperate line.

Test this first.
'==========================================================================
'
' NAME: <MemProcDiskInventory.vbs>
'
' AUTHOR: Mark D. MacLachlan , ITSynergy
' DATE  : 5/15/2003
'
' COMMENT: <Inventories computer configuration and writes report to disk>
'==========================================================================
on error resume Next

Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
InputFile = "Computers.txt"	' Input text file with list of servers
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(InputFile,1,FALSE) ' opens text file object
Do Until objInputFile.AtEndOfStream	' sets loop until end of input file ios reached
strComputer = (objInputFile.Readline)	' sets input for each computer listed in input file
'strComputer = env.Item("Computername") 'Commented out
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")


report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
    report = report &  strComputer  & vbCrLf & "OS Details"& vbCrlf
    report = report &  "Caption: " & objItem.Caption & vbCrLf
    report = report &  "Description: " & objItem.Description & vbCrLf
    report = report &  "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
    report = report &  "InstallDate: " & objItem.InstallDate & vbCrLf
    report = report &  "Manufacturer: " & objItem.Manufacturer & vbCrLf
    report = report &  "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
    report = report &  "Name: " & objItem.Name & vbCrLf
    report = report &  "Organization: " & objItem.Organization & vbCrLf
    report = report &  "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
    report = report &  "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
    report = report &  "SerialNumber: " & objItem.SerialNumber & vbCrLf
    report = report &  "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion & vbCrLf
    report = report &  "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
    report = report &  "Version: " & objItem.Version & vbCrLf
    report = report &  "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings 
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_Processor")
For Each objProcessor in colSettings 
report = report & objProcessor.Description & " Processor" & vbCrLf
Next

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
report = report & objLogicalDisk.FreeSpace /1024\1024+1 & "MB Free Disk Space" & vbCrLf
report = report & objLogicalDisk.Size /1024\1024+1 & "MB Total Disk Space" & vbCrLf

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = vbCrLf & "******************************************" & vbCrLf
software = software & vbCrLf & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
    software = software & subkey & vbCrLf
End If
Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile (strComputer & ".txt", ForWriting)
ts.write report
ts.write software
'MsgBox Report
MsgBox "Done"

Open in new window

0
 

Author Closing Comment

by:samymac
ID: 35467421
A++++++

Had to add the "loop" on line 89 but it works a treat thanks again
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question