Help With a Script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
othman
Posts: 145
Joined: Wed Nov 07, 2007 5:47 pm

Help With a Script

Post by othman »

small error:
it is missing:"" strMoveTo = "serverDRalternateLogs"
should be: strMoveTo = "serverDRalternateLogs"

User avatar
camobarbie
Posts: 8
Joined: Tue Feb 26, 2008 11:45 pm

Help With a Script

Post by camobarbie »

Yay it works. Now the magical question is. Ive got that to work. I want to get the event files moved to that drive but their corresponding folder. For example I have consetta-dc (name of server) I want all the .evt files for that server to go in a folder called consetta-dc located in the strMoveTo path

User avatar
othman
Posts: 145
Joined: Wed Nov 07, 2007 5:47 pm

Help With a Script

Post by othman »

Should look like this:

Code: Select all

'On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oTS = FSO.OpenTextFile("c:computers.txt")
Do Until oTS.AtEndOfStream
    strComputer = oTS.ReadLine
strMoveTo = "ServerLogsEventView_logs" & strComputer & ""
If FSO.FolderExists(strMoveTo) Then
   Set objFolder = FSO.GetFolder(strMoveTo)
Else
   Set objFolder = FSO.CreateFolder(strMoveTo)
End If
   
    Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,"rootCIMV2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NTEventlogFile")
   
    For Each objItem In colItems
        strDate = Replace(Date, "/", "-")
          strDriveName = "C:"
          strFileName = strComputer & "-" & objItem.LogfileName & "-" & strDate & ".evt"
          sFileName = strDriveName & strFileName
         
        LogfileName strComputer, objItem.LogfileName, sFileName
  
  strPath = "" & strComputer  & "c$"
    Next
 
Set objFolder = FSO.GetFolder(strPath)
Set objFiles = objFolder.Files
    For Each objItem In objFiles
  If InStr(objItem.Name,".evt") <> 0 Then
   WScript.Echo objItem
   FSO.MoveFile objItem, strMoveTo
  End If
 Next
Loop

Sub LogfileName(sComputer, strEventLog, sBackupFile)
      Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate" & _
      ",(Backup, Security)}!" & strComputer & "rootcimv2")
      Set colLogs = objWMI.ExecQuery("Select * from Win32_NTEventlogFile Where " & _
      "" & " Logfilename = '" & strEventLog & "'")
      
      For Each objLog In colLogs
           errBackupLog = objLog.BackupEventLog( sBackupFile )
        If errBackupLog <> 0 Then
            Select Case errBackupLog
            Case    3: strError = "Invalid Location or Folder doesn't exists " & sBackupFile
            Case    5: strError = "Access Denied" & sBackupFile
            Case    8: strError = "Privilege missing"
            Case   21: strError = "Invalid parameter"
            Case   80: strError = "Archive file name already exists" 'Vista and later
            Case  123: strError = "Funny error code 123" ' usually means format for file name is wrong
            Case  183: strError = "Archive file name already exists" ' pre-vista
            Case Else: strError = "Unknown Error:" & errBackupLog
            End Select
              WScript.Echo strEventLog & " backed up FAILED with error:" & strError
          Else
              WScript.Echo strEventLog & " backed up to " & sBackupFile
            objLog.ClearEventLog()
          End If
      Next
End Sub 
othman2008-04-03 05:54:40

User avatar
camobarbie
Posts: 8
Joined: Tue Feb 26, 2008 11:45 pm

Help With a Script

Post by camobarbie »

Hmm, for some reason it is only backing it up too the root of the unc pathServerLogsEventView_logs

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

Help With a Script

Post by donj »

Watch your variables. Your subroutine is accepting sFilename as input, and that's what it's backing up to. I don't see where your strMoveTo path is being passed into that subroutine or even used.

User avatar
othman
Posts: 145
Joined: Wed Nov 07, 2007 5:47 pm

Help With a Script

Post by othman »

I get your point, but first it will back up to local c: then copy to network location. due the security reason for "Security" event log as you can't back up it to unc path.
it passes:

Code: Select all

	
   FSO.MoveFile objItem, strMoveTo
othman2008-04-07 07:43:33

Locked