Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inventory machine hardware, etc.. 11

Status
Not open for further replies.

bmquiroz

IS-IT--Management
Sep 26, 2003
207
0
0
US
I need to inventory several workstations and servers and need a script to automate this process. I know this could be accomplished using WMI so if any one has code that they can pass on, I would appreciate it. I basically need a script that will enumerate drives, shares, get memory size, CPU speed, OS version and SP, etc..

Thanks!
 
Hi Acewilli,

Let me describe how I use this script. I have about 100 workstations that run this script at logon with a GPO. If you can not change any current GPO's then maybe create a new one. I have created a GPO that is just linked to the all users OU that does not include enterprise users. Within the GPO under user config, windows settings, scripts, logon I locate the VBS that I saved in the Netlogon share. Within the VBS I have specified it to save the results another network share that all users have full access to write to thus giving me a text file for each machine. I have found this to be very effective and does not slow login time down at all. Also the addition of recording the Dell service tag helped.

I hope this explains what I use it for and may help someone else!

STU
 
Seems you guys are really trying to just generate reports on hotfixes and not so interested int he hardware inventory. You should be aware the WSUS can give you very detailed reports and so can MBSA 2.0.

Both are free tools from Microsoft. WSUS can apply or remove a patch for you and generate a report of what is installed and what is needed.

MBSA will give you a list of what is needed.

I hope you find this post helpful.

Regards,

Mark
 
So, I have another modification...... I need to record the mac address of the machine that this script audits.

I have added in the code. The entire script is below (sorry, I know it's getting a bit long these days). The problem is that when I run the script the results have about 15 mac address! I do only have 1 nic in the machine so can anyone tell me where I'm doing wrong?

Cheers

STU
--------------------------

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 & "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
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf

Next

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

Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
report = report & "DellserviceTag: " & objSMBIOS.SerialNumber & vbCrLf

next


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapter")
For Each objItem in colItems

report = report & "Mac Address: " & objItem.MACAddress & 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 = software & vbCrLf & "******************************************" & vbCrLf
software = software & "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 ("\\tlnas\logs\" & strComputer & ".txt", ForWriting)
ts.write report
ts.write software
 
you might want to be more selective about the which Win32_networkadaptor instance you retrieve..i.e. one which has IPEnabled etc etc, or you might just want to make use of a dictionary object to add the addresses you find? if the machine has more than one NIC etc, the dictionary object will do the uniqueness stuff for you
 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
For Each objItem in colItems
report = report & "Mac Address: " & objItem.MACAddress & vbCrLf
Next


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV

Perfect!!! Thank you very much, it works great now.
:)

STU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top