It was not enough to create the inventory till it fetched the details on email IDs thus created one which could send the details to any requester email ID. This script is necessary in case shared path at which we wanted to save the inventory is not accessible or we have to send it straight to someone on his email only.
Start from right below -
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
ff=wshNetwork.ComputerName
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
Model = objItem.Model
RAM = Int(objItem.TotalPhysicalMemory /(100000000))
timenow = Now
Next
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each os in oss
OSystem = os.Caption
Next
For each objBIOS in colBIOS
Manufacturer = objBIOS.Manufacturer
Serial= objBIOS.SerialNumber
Next
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure",,16)
For Each objChassis in colChassis
For Each objItem in objChassis.ChassisTypes
Select Case objItem
Case 1 strChassis = "Maybe Virtual Machine"
Case 2 strChassis = "??"
Case 3 strChassis = "Desktop"
Case 4 strChassis = "Thin Desktop"
Case 5 strChassis = "Pizza Box"
Case 6 strChassis = "Mini Tower"
Case 7 strChassis = "Full Tower"
Case 8 strChassis = "Portable"
Case 9 strChassis = "Laptop"
Case 10 strChassis = "Notebook"
Case 11 strChassis = "Hand Held"
Case 12 strChassis = "Docking Station"
Case 13 strChassis = "All in One"
Case 14 strChassis = "Sub Notebook"
Case 15 strChassis = "Space-Saving"
Case 16 strChassis = "Lunch Box"
Case 17 strChassis = "Main System Chassis"
Case 18 strChassis = "Lunch Box"
Case 19 strChassis = "SubChassis"
Case 20 strChassis = "Bus Expansion Chassis"
Case 21 strChassis = "Peripheral Chassis"
Case 22 strChassis = "Storage Chassis"
Case 23 strChassis = "Rack Mount Unit"
Case 24 strChassis = "Sealed-Case PC"
End Select
Next
Next
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
MAC = Nic.MACAddress
end If
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
CPU = objItem.Name
Next
on error resume next
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf, strReport
strReport = strReport & "<body>"
strReport = strReport & "<div align='center'>"
strReport = strReport & "<br>"
strReport = strReport & "<table border='1' style='border-collapse: collapse'>"
strReport = strReport & "<tr bgcolor='#fff' bordercolor='#222' size='2'>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & wshNetwork.UserName & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & strChassis & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & Manufacturer & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & Model & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & Serial & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & wshNetwork.ComputerName & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & CPU & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & RAM & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & HDD & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & StrIP & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & MAC & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & OSystem & "</Font size></td>"
strReport = strReport & "<td width='20' align= 'right'>" & FormatDateTime(Date(),1) & "</td>"
strReport = strReport & "</tr>"
strReport = strReport & "</table>"
' E-mail properties
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "baij.rathore@one97.net" ' or "Sender Name <baij.rathore@one97.net>"
oMsg.To = "baij.rathore@one97.net" ' or "Recipient Name <baij.rathore@one97.net>"
oMsg.Subject = "Test from VBScript"
oMSG.HTMLBody = strReport
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com" 'server address
oConf.Fields(schema & "smtpserverport") = 465 'port number
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic 'authentication type
oConf.Fields(schema & "smtpusessl") = True 'use SSL encryption
oConf.Fields(schema & "sendusername") = "brathoreit@gmail.com" 'sender username
oConf.Fields(schema & "sendpassword") = "*********" 'sender password
oConf.Fields.Update()
' send message
oMsg.Send()
' Return status message
If Err Then
resultMessage = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear()
Else
resultMessage = "Message sent ok"
End If
Set wshNetwork.UserName = Nothing
Set strChassis = Nothing
Set Manufacturer = Nothing
Set Model = Nothing
Set Serial = Nothing
Set wshNetwork.ComputerName = Nothing
Set CPU = Nothing
Wscript.echo(resultMessage)
Ending till above line.
Regards, Baij
Start from right below -
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
ff=wshNetwork.ComputerName
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
Model = objItem.Model
RAM = Int(objItem.TotalPhysicalMemory /(100000000))
timenow = Now
Next
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each os in oss
OSystem = os.Caption
Next
For each objBIOS in colBIOS
Manufacturer = objBIOS.Manufacturer
Serial= objBIOS.SerialNumber
Next
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure",,16)
For Each objChassis in colChassis
For Each objItem in objChassis.ChassisTypes
Select Case objItem
Case 1 strChassis = "Maybe Virtual Machine"
Case 2 strChassis = "??"
Case 3 strChassis = "Desktop"
Case 4 strChassis = "Thin Desktop"
Case 5 strChassis = "Pizza Box"
Case 6 strChassis = "Mini Tower"
Case 7 strChassis = "Full Tower"
Case 8 strChassis = "Portable"
Case 9 strChassis = "Laptop"
Case 10 strChassis = "Notebook"
Case 11 strChassis = "Hand Held"
Case 12 strChassis = "Docking Station"
Case 13 strChassis = "All in One"
Case 14 strChassis = "Sub Notebook"
Case 15 strChassis = "Space-Saving"
Case 16 strChassis = "Lunch Box"
Case 17 strChassis = "Main System Chassis"
Case 18 strChassis = "Lunch Box"
Case 19 strChassis = "SubChassis"
Case 20 strChassis = "Bus Expansion Chassis"
Case 21 strChassis = "Peripheral Chassis"
Case 22 strChassis = "Storage Chassis"
Case 23 strChassis = "Rack Mount Unit"
Case 24 strChassis = "Sealed-Case PC"
End Select
Next
Next
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
MAC = Nic.MACAddress
end If
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
CPU = objItem.Name
Next
on error resume next
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf, strReport
strReport = strReport & "<body>"
strReport = strReport & "<div align='center'>"
strReport = strReport & "<br>"
strReport = strReport & "<table border='1' style='border-collapse: collapse'>"
strReport = strReport & "<tr bgcolor='#fff' bordercolor='#222' size='2'>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & wshNetwork.UserName & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & strChassis & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & Manufacturer & "</Font size></td>"
strReport = strReport & "<td colspan='2' align='center'><Font size = '2'>" & Model & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & Serial & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & wshNetwork.ComputerName & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & CPU & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & RAM & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & HDD & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & StrIP & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & MAC & "</Font size></td>"
strReport = strReport & "<td width='80' colspan='2' align='center'><Font size = '2'>" & OSystem & "</Font size></td>"
strReport = strReport & "<td width='20' align= 'right'>" & FormatDateTime(Date(),1) & "</td>"
strReport = strReport & "</tr>"
strReport = strReport & "</table>"
' E-mail properties
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "baij.rathore@one97.net" ' or "Sender Name <baij.rathore@one97.net>"
oMsg.To = "baij.rathore@one97.net" ' or "Recipient Name <baij.rathore@one97.net>"
oMsg.Subject = "Test from VBScript"
oMSG.HTMLBody = strReport
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com" 'server address
oConf.Fields(schema & "smtpserverport") = 465 'port number
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic 'authentication type
oConf.Fields(schema & "smtpusessl") = True 'use SSL encryption
oConf.Fields(schema & "sendusername") = "brathoreit@gmail.com" 'sender username
oConf.Fields(schema & "sendpassword") = "*********" 'sender password
oConf.Fields.Update()
' send message
oMsg.Send()
' Return status message
If Err Then
resultMessage = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear()
Else
resultMessage = "Message sent ok"
End If
Set wshNetwork.UserName = Nothing
Set strChassis = Nothing
Set Manufacturer = Nothing
Set Model = Nothing
Set Serial = Nothing
Set wshNetwork.ComputerName = Nothing
Set CPU = Nothing
Wscript.echo(resultMessage)
Ending till above line.
Regards, Baij
No comments:
Post a Comment