• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3148
  • Last Modified:

Local Result Only::strComputer = "."

Why does this script return a result from the local machine when I use send it a remote computer name?
usage: cscript eventLogScan.vbs  remote-computer-name

The script will return the eventlog result from the local PC the script is running on, versus the remote PC's event logging.

'Purpose of script to query Application log for Successful Telestaff Installs

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' AND EventCode = '302' AND Message like '%Telestaff%-%Install%'")


For Each objItem in colLoggedEvents
wscript.Echo "EventCode: " & objItem.EventCode
wscript.Echo "TimeGenerated: " & objItem.TimeGenerated
Wscript.Echo "Message: " & objItem.Message

Wscript.Echo "Occurrances of Telestaff Installs: " & colLoggedEvents.Count
thisDateTime = objItem.TimeGenerated
Wscript.Echo objItem.TimeGenerated
Wscript.Echo objItem.TimeWritten
WScript.Echo dConvertWMItoVBSDate(thisDateTime)


JustTime = Hour(dConvertWMItoVBSDate(thisDateTime)) & ":" & Minute(dConvertWMItoVBSDate(thisDateTime)) &":" & Second(dConvertWMItoVBSDate(thisDateTime))

WScript.Echo JustTime
Next

Private Function dConvertWMItoVBSDate(sDate)
  Dim sMonth, sDay, sYear, sHour, sMinutes, sSeconds
  sMonth = Mid(sDate,5,2)
  sDay = Mid(sDate,7,2)
  sYear = Mid(sDate,1,4)
  sHour = Mid(sDate,9,2)
  sMinutes = Mid(sDate,11,2)
  sSeconds = Mid(sDate,13,2)
  dConvertWMItoVBSDate = DateSerial (sYear, sMonth, sDay) + TimeSerial (sHour, sMinutes, sSeconds)
End Function
 

0
danfiggolf
Asked:
danfiggolf
1 Solution
 
ghostdog74Commented:
>>> strComputer = "."

change this to the computer you are querying
0
 
RobSampsonCommented:
Hi,

The strComputer = "." will make the script run against the local machine all the time.

Since you want:
cscript eventLogScan.vbs  remote-computer-name

You will need to change that line to:
strComputer = WScript.Arguments.Item(0)

But just in case you do run it locally, you'll want to check if an argument was passed or not, so this will do that:

'==================
'Purpose of script to query Application log for Successful Telestaff Installs

If WScript.Arguments.Count = 1 Then
      strComputer = WScript.Arguments.Item(0)
Else
      strComputer = "."
End If

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' AND EventCode = '302' AND Message like '%Telestaff%-%Install%'")


For Each objItem in colLoggedEvents
wscript.Echo "EventCode: " & objItem.EventCode
wscript.Echo "TimeGenerated: " & objItem.TimeGenerated
Wscript.Echo "Message: " & objItem.Message

Wscript.Echo "Occurrances of Telestaff Installs: " & colLoggedEvents.Count
thisDateTime = objItem.TimeGenerated
Wscript.Echo objItem.TimeGenerated
Wscript.Echo objItem.TimeWritten
WScript.Echo dConvertWMItoVBSDate(thisDateTime)


JustTime = Hour(dConvertWMItoVBSDate(thisDateTime)) & ":" & Minute(dConvertWMItoVBSDate(thisDateTime)) &":" & Second(dConvertWMItoVBSDate(thisDateTime))

WScript.Echo JustTime
Next

Private Function dConvertWMItoVBSDate(sDate)
  Dim sMonth, sDay, sYear, sHour, sMinutes, sSeconds
  sMonth = Mid(sDate,5,2)
  sDay = Mid(sDate,7,2)
  sYear = Mid(sDate,1,4)
  sHour = Mid(sDate,9,2)
  sMinutes = Mid(sDate,11,2)
  sSeconds = Mid(sDate,13,2)
  dConvertWMItoVBSDate = DateSerial (sYear, sMonth, sDay) + TimeSerial (sHour, sMinutes, sSeconds)
End Function
'==============

Regards,

Rob.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now