I am running an inventory script that I want to check a logfile that has date in the txt file and then if it's over a month old run rest of script. Not sure if i should have to run a different vbs or if code should be in the if/then statement. When i try to do it with code inside i keep getting errors. I am new to scripting. I have learned a lot from this forum and really at a loss of how to get this to work correctly. Thanks for Help.
'INVENTORY SCRIPT works on dell's and ibm's i know of
'August 9, 2009
Dim objNTInfo
Dim ComputerName
Set objNTInfo = CreateObject("WinNTSystemInfo")
strComputer = lcase(objNTInfo.ComputerName)
strMyEmailAddr = "sendfrom@email.com"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
Set colItems2 = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
strSerial = objItem.SerialNumber
Next
Set wshShell = Wscript.CreateObject( "Wscript.Shell" )
Function model(strComputer)
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objItem in colItems
model = objItem.Model
next
End Function
' Network Adapter Details
For Each objItem In colItems2
ipaddress = objitem.ipaddress(0)
mac = objitem.MACaddress
next
' Operating System including Service Pack level.
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
WKOS = objItem.Caption
ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion
Next
'==Message boxes.
UserName = InputBox("What is the User Name?","UserName","")
RoomNum = InputBox("What is PHYSICAL room number? DOUBLE CHECK!","RoomNum","")
TechName = InputBox("What is YOUR UCA?","TechUCA","")
'VbCrLF= A return in message boxes
' VbTAB=A tab for csv , makes move to new box
'=====Display box to check info and body of Email===
Strmsg = Strmsg _
& " DOUBLE CHECK AND CONFIRM THIS!!" & VbCrLF _
& " Computer Name : " & wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) & VbCrLF _
& " User Name: " & UserName & VbCrLF _
& " Physical Location: " & RoomNum & VbCrLF _
& " Your Serial: " & strSerial & VbCrLF _
& " Model: " & model(strComputer) & VbCrLF _
& " OS: " & wkos & servicepack & VbCrLF _
& " IP: " & ipaddress & VbCrLF _
& " Tech's Name: " & techname & VbCrLF _
& " Date: " & now() & VbCrLF _
& " MAC Address: " & mac
'=====CSV file info for backup server====
Strmsg1 = Strmsg1 _
& wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) & VbTAB & ","_
& UserName & VBTAB & ","_
& RoomNum & VbTAB & ","_
& strSerial & VbTAB & ","_
& model(strComputer) & VbTAB & ","_
& wkos & servicepack & VbTAB & ","_
& ipaddress & VbTAB & ","_
& " Tech's Name: " & techname & VbTAB _
& now() & VbTAB & ","_
& mac
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) & " " & "STAFF Inventory Info"
objMessage.From = strMyEmailAddr
objMessage.To = "sendto@email.com"
objMessage.TextBody = Strmsg
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.smtpserver.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
'====Backup csv file creation===
Dim strDirectory, strFile, strText
strDirectory = "\LABinvent\"
strFile = "Maininventory.csv"
strText = strmsg1
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close
WScript.echo strmsg
'====Logfile Creation======
Dim strLogDirectory, strLogFile, strLogText
strlogDirectory = "c:\logs\"
strLogFile = "inventlog.txt"
strLogText = now()
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strLogDirectory folder exists
If objFSO.FolderExists(strLogDirectory) Then
Set objFolder = objFSO.GetFolder(strLogDirectory)
Else
Set objFolder = objFSO.CreateFolder(strLogDirectory)
WScript.Echo "Just created " & strLogDirectory
End If
If objFSO.FileExists(strLogDirectory & strLogFile) Then
Set objFolder = objFSO.GetFolder(strLogDirectory)
Else
Set objFile = objFSO.CreateTextFile(strLogDirectory & strLogFile)
Wscript.Echo "Just created " & strLogDirectory & strLogFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForWriting = 2
Set objTextFile = objFSO.OpenTextFile _
(strLogDirectory & strLogFile, ForWriting, True)
' Writes strlogText every time you run this VBScript
objTextFile.WriteLine(strLogText)
objTextFile.Close