Link to home
Start Free TrialLog in
Avatar of Danny Child
Danny ChildFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Script to capture or inventory amount of RAM - WMI?

Hi,
I'm trying to capture the amount of physical RAM memory installed in one of our offices.  There have been a few cases of sticks going "missing" and I'd like to be able to audit this quickly and regularly in the future.  I hear good things about WMI, but this is new to me.  Anyone got a few pointers on where to start with this?  I'd like to run the script on one pc against a list of all machines in the office, and have it collate a simple text list of the RAM amounts found.

Situation - AD Domain, XP clients pcs (SP1), W2000 servers (if that's relevant...).  High points 'cos I'm on holiday soon, and would like to sort this first!

cheers,
Danny
Avatar of sramesh2k
sramesh2k
Flag of India image

Hi Danny,

Michael Harris posted this script - Enumerates the list of workstations (stored in a text file), and queries the amount of Total Physical memory in each system in a network.

http://groups.google.co.in/group/microsoft.public.scripting.vbscript/msg/0df09ec3a2ccc50b

In that example, the file "c:\downlo­ad\admin\servers.txt" stored the list of computer names.

SOLUTION
Avatar of JBlond
JBlond
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Danny Child

ASKER

cool.  this is why this place is soooo good.

Sramesh, the 2nd script was perfect.
I just copied the lines between the ========= to a new txt file, renamed it RAMaudit.vbs, tweaked the FinalOutput.txt and c:\servers.txt filenames to match my environment, and ran it with a doubleclick.  Output to the desktop was fine.
The first script worked too, but did an output to screen, rather than file, so that wasn't ideal.

One other way I found out was to use Dameware Utilities to display the Ram for each pc under Properties.. System tab, but that was a manual pointandclick for each pc.  

JBlond, thanks for your help too.  I think the script you mentioned doesn't capture RAM, but CPU info, etc, and it wasn't great for me as I don't want to go monkeying with the logon scripts.  

The servicedesk link looks interesting too.  Most points to Sramesh for the perfect fix, but JBlond was quick and useful too, so some there as well.  Superb.
cheers, Danny
Brilliant feedback Danny. Glad it worked out well for you :-)
Danny,

As you stated that all of your client systems are running Windows XP OS, I'd like to tell that there is another simple version of the code (that runs only in Windows XP and above). No temp files are created and no hassle.

================================================
'Ramesh Srinivasan
'Use the Win32_PingStatus provider to check the online presence

Const ForReading = 1
Const TextMode = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'-----------------------------------------------------
'The final output file that you need - FinalOutput.txt
'-----------------------------------------------------

fName = objShell.SpecialFolders("Desktop")
fName = fName & "\FinalOutput.txt"
set b = objFSO.CreateTextFile(fName, true)
b.writeline "List of all the computers and their Physical Memory info"
b.writeline string(56,"~")
b.writeblanklines 1

'-----------------------------------------------------------------------------------
' Input file, containing the list of computer names in your network - C:\Servers.txt
'-----------------------------------------------------------------------------------

Set objTextFile = _
  objFSO.OpenTextFile("c:\servers.txt",ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each StrComputer in objDictionary.Items

If IsOnline(strComputer) Then
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery(_
      "Select * from Win32_ComputerSystem",,48)
    For Each objComputerSystem in colItems
       b.writeline "Computer Name : " & strComputer
       b.writeline "PhysicalMemory: " _
                 & round(((objComputerSystem.TotalPhysicalMemory/1024)/1024),0)
       b.writeblanklines 1
    Next
else
       b.writeline strComputer & " Computer is Offline or unavailable"
       b.writeblanklines 1
end if

Next

'-----------------------------------------------------------------
' Verify if the target computer is Online.
'-----------------------------------------------------------------

Function IsOnline(sHost)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPings = objWMIService.ExecQuery _
    ("Select * from Win32_PingStatus " & _
        "Where Address = '" & sHost & "'")

For Each objStatus in colPings
    If IsNull(objStatus.StatusCode) _
        or objStatus.StatusCode<>0 Then
        IsOnline = False
    Else
        IsOnline = True
    End If
Next

End Function

b.writeline string(56,"~")
b.close
objShell.Run "notepad.exe " & fName, 1,True

Set objFSO = Nothing
set objShell = Nothing
========================================================