We help IT Professionals succeed at work.

Get multiple computer details and send them by mail using a script

425 Views
Last Modified: 2012-05-08
I need a script that on logon will get the following information and send them to me by mail.

The information I need are

computer name, computer description,  Physical Memory, Hard disk space and OS.

All computers are either xp or windows 2000
Comment
Watch Question

Ove

Commented:
i would add a batch-file which grabs all yr info needed and writes it to a textfile of yr choice which is that be mailed to you

you will get most of your info with on-board tools

i.e.:
echo %COMPUTERNAME% >> c:\info.txt
ver >> c:\info.txt

have a look at "systeminfo" on winXP and the rest you'll find inside the registry which can be queried by the free tool REG.EXE from microsoft
Ove

Commented:
ahh...forgot the mail-proggy of my choice :-)

http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm
bmail is a little/free tool for this...you may freely distribute it to every of your machines.
Here is a VBS that may help
Set objMessage = CreateObject("CDO.Message") 
Dim strComputerName, strMemory, strHardDisk, strDescription 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
	strMemory = Round(procItem.Capacity / 1048576, 0) & " MB"
Next 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
	strHardDisk = Round(procItem.Size / 1073741824, 0) & "GB"
Next 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
	strComputerName =  procItem.Name
Next 
For Each procItem in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
	strDescription = procItem.Description
Next 
objMessage.Subject = "Computer Inventory" ' Any subject you want
objMessage.From = "IT@test.com" ' The From field of the email
objMessage.To = "ITDept@test.com" ' A valid email address to send it to
' The body of the email goes here
objMessage.TextBody = "ComputerName: " & strComputerName & vbCrLf & "Computer Description: " & strDescription & vbCrLf & "Totla Memory: " & strMemory & vbCrLf & "HD size: " & strHardDisk
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your SMTP server here
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver" 
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update 
objMessage.Send

Open in new window

Wow, I'm going to have to be quicker with my script writing. I was halfway done writing a script when I noticed the post from "TheNautican". This is much a better way of doing this then I was planning anyway, (I was going to use a command-line tool for sending the message, as I did not know there was a vbscript command to send mail). So, instead of posting what I little had, I scrapped it and made some minor changes to yours Nautican.

I added the OS version as requested, and fixed an issue with the memory size being reported incorrectly. I also did some miscellaneous restructuring for easier readability.
Option Explicit
Dim objMessage
Dim colItem
Dim strComputerName, strMemory, strHardDisk, strDescription, strMailServer, strOSversion
Dim strDay, strMonth, strYear, strHour, strMinute, strSecond
Dim intMailServerPort
set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Computer Inventory" ' The subject for the email.
objMessage.From = "user1@domain.com" ' The "From" field of the email.
objMessage.To = "user2@domain.com" ' A valid email address to send it to.
strMailServer = "domain.com" ' Your mail server name (preferably the FQDN).
intMailServerPort = "25" ' The port your mail server uses for SMTP. 
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
        strComputerName =  colItem.Name
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        strDescription = colItem.Description
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_LogicalMemoryConfiguration")
        strMemory = Round(colItem.TotalPhysicalMemory / 1024, 0) & " MB"
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_DiskDrive")
        strHardDisk = Round(colItem.Size / 1073741824, 2) & " GB"
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        strOSversion = colItem.Caption
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        strOSversion = strOSversion & " SP" & colItem.ServicePackMajorVersion
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        strOSversion = strOSversion & " v" & colItem.Version
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strDay = colItem.Day
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strMonth = colItem.Month
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strYear= colItem.Year
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strHour = colItem.Hour
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strMinute = colItem.Minute
Next
For Each colItem in GetObject("winmgmts:").InstancesOf("Win32_CurrentTime")
        strSecond = colItem.Second
Next 
objMessage.TextBody = "Computer inventory report taken " & strDay & "/" & strMonth & "/" & strYear & " " & strHour & ":" & strMinute & ":" & strSecond & vbCrLf & _
	"==================================================" & vbCrLf & vbCrLf & _
	"Computer Name:" & Chr(9) & Chr(9) & strComputerName & vbCrLf & _
	"Computer Description:" & Chr(9) & strDescription & vbCrLf & _
	"Total Memory:" & Chr(9) & Chr(9) & strMemory & vbCrLf & _
	"Hard Disk Size:" & Chr(9) & Chr(9) & strHardDisk & vbCrLf & _
	"OS Version:" & Chr(9) & Chr(9) & strOSversion
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strMailServer
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = intMailServerPort
objMessage.Configuration.Fields.Update
objMessage.Send

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
OK, cool. I was wondering if I could do that... I wasn't sure exactly how the data looks when as it get's fed through those for loops, so I didn't want to take any chances. Good to know!

Author

Commented:
Hi Guys,

Thanks for all your promply posts.  just one problem / improvements.  The script windows does not close after the scrips run (either purposly or the script is not exiting).

is it possible that the script windows will not be shown to the user?  if now  is it possible to close it automatically?

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
How can i run it from gpo?
Ove

Commented:
as User-Start-script :
GPO-Editor-> User-configuration -> Policies -> Windows-Settings -> Script -> Login
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.