Danny Child
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.Di ctionary")
Set objShell = CreateObject("WScript.Shel l")
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
'------------------------- ---------- ---------- --------
'The final output file that you need - FinalOutput.txt
'------------------------- ---------- ---------- --------
fName = objShell.SpecialFolders("D esktop")
fName = fName & "\FinalOutput.txt"
set b = objFSO.CreateTextFile(fNam e, 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:\se rvers.txt" ,ForReadin g)
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=imper sonate}!\\ " _
& 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. TotalPhysi calMemory/ 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:\\.\ro ot\cimv2")
Set colPings = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & sHost & "'")
For Each objStatus in colPings
If IsNull(objStatus.StatusCod e) _
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
========================== ========== ========== ==========
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.Di
Set objShell = CreateObject("WScript.Shel
Set objFSO = CreateObject("Scripting.Fi
'-------------------------
'The final output file that you need - FinalOutput.txt
'-------------------------
fName = objShell.SpecialFolders("D
fName = fName & "\FinalOutput.txt"
set b = objFSO.CreateTextFile(fNam
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:\se
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=imper
& 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.
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:\\.\ro
Set colPings = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & sHost & "'")
For Each objStatus in colPings
If IsNull(objStatus.StatusCod
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
==========================
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:\download\admin\server