2/29/2008

vbscript for backup all event logs and delete them afterwards

  1. Option Explicit  
  2. dim strComputer  
  3. dim objWMIService  
  4. dim colLogFiles  
  5. dim objLogfile  
  6. dim errBackupLog  
  7.   
  8. strComputer = "." 'IP Address or Name  
  9. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" & strComputer & "\root\cimv2")  
  10.   
  11. Call eventlogbackup("Application")  
  12. Call eventlogbackup("System")  
  13. Call eventlogbackup("Security")  
  14. 'Call eventlogbackup("DNS Server") Define further logs here  
  15.   
  16. Function eventlogbackup(logtype)  
  17. Set colLogFiles = objWMIService.ExecQuery ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='" &logtype &"'")  
  18. For Each objLogfile in colLogFiles  
  19.    errBackupLog = objLogFile.BackupEventLog("\\server\eventlogs\" &strComputer &"\" &logtype &".evt")  
  20.    If errBackupLog <> 0 Then  
  21.       Wscript.Echo "The " &logtype &" event log could not be backed up."  
  22.    Else  
  23.       objLogFile.ClearEventLog()  
  24.       Wscript.Echo "The " &logtype &" event log is backed up."  
  25.    End If  
  26. Next  
  27. End Function  

2/28/2008

vbscript to check if a computer is available

  1. Option Explicit  
  2. dim objPing  
  3. dim objStatus  
  4. dim strComputer  
  5.   
  6. strComputer="." 'IP Address or Name  
  7. Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._  
  8. ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")  
  9.   
  10. For Each objStatus in objPing  
  11.  If  IsNull(objStatus.ReplySize) Then  
  12.   WScript.Echo "computer is offline"  
  13.   '...  
  14.  Else  
  15.   WScript.Echo "computer is online"  
  16.   '...  
  17.  End If  
  18. Next  
  19.   
  20. Set objPing=Nothing  
  21. Set objStatus=Nothing  

What's this blog for?

welcome to my blog :)
in this blog i'll publish some technical information regarding my daily work as IT consultant.
Mainly this posts will treat the following themes:
- scripting (vbscript, vb, vba & windows scripting host, ...)
- windows (deployment, automation, 2k3, 2k8, xp & vista, ...)
- office (deployment, 2k7, ...)
- servers (sms, sql, sccm, isa, iis, ias,...)
- in summary: the daily IT doing

so come in soon...