Board index » Visual Studio » copying event logs

copying event logs

Visual Studio243
Trying to create a simple script that will be called by batch file to copy a

server's event logs to a central location:

called by "cscript evt-backup.vbs servername"



====== evt-backup.vbs=========

if wscript.arguments.count < 1 then

wscript.echo "Requires server name!"

wscript.quit

end if



strComputer = wscript.arguments(0)

If left(strComputer,2) <>"\\" then

strComputer = "\\" & strComputer

End if



Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

& strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _

("SELECT * FROM Win32_NTEventLogFile")

For Each objLogfile in colLogFiles

strBackupLog = objLogFile.BackupEventLog _

("c:\scripts\" & substr(strComputer,2) & objLogFile.LogFileName & ".evt")

Next







The main portion was gotten from the technet script center, but it is

receiving errors:



C:\Scripts\evt-backup.vbs(11, 1) (null): 0x80041021



Line 11 begins with the "Set objWMIService"



Thanks

Carl


-
 

Re:copying event logs

Try without;



If left(strComputer,2) <>"\\" then

strComputer = "\\" & strComputer

End if



--

Regards,



Dave Patrick ....Please no email replies - reply in newsgroup.

Microsoft Certified Professional

Microsoft MVP [Windows]

www.microsoft.com/protect">www.microsoft.com/protect



"Carl Hilton" wrote:

| Trying to create a simple script that will be called by batch file to copy

a

| server's event logs to a central location:

| called by "cscript evt-backup.vbs servername"

|

| ====== evt-backup.vbs=========

| if wscript.arguments.count < 1 then

| wscript.echo "Requires server name!"

| wscript.quit

| end if

|

| strComputer = wscript.arguments(0)

| If left(strComputer,2) <>"\\" then

| strComputer = "\\" & strComputer

| End if

|

| Set objWMIService = GetObject("winmgmts:" _

| & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

| & strComputer & "\root\cimv2")

| Set colLogFiles = objWMIService.ExecQuery _

| ("SELECT * FROM Win32_NTEventLogFile")

| For Each objLogfile in colLogFiles

| strBackupLog = objLogFile.BackupEventLog _

| ("c:\scripts\" & substr(strComputer,2) & objLogFile.LogFileName & ".evt")

| Next

|

|

|

| The main portion was gotten from the technet script center, but it is

| receiving errors:

|

| C:\Scripts\evt-backup.vbs(11, 1) (null): 0x80041021

|

| Line 11 begins with the "Set objWMIService"

|

| Thanks

| Carl

|

|





-

Re:copying event logs

Thanks, I missed the original script adding the "\\".



Carl





"Dave Patrick" <mail@Nospam.DSPatrick.com>wrote in message

Quote
Try without;



If left(strComputer,2) <>"\\" then

strComputer = "\\" & strComputer

End if



--

Regards,



Dave Patrick ....Please no email replies - reply in newsgroup.

Microsoft Certified Professional

Microsoft MVP [Windows]

www.microsoft.com/protect">www.microsoft.com/protect



"Carl Hilton" wrote:

| Trying to create a simple script that will be called by batch file to

copy

a

| server's event logs to a central location:

| called by "cscript evt-backup.vbs servername"

|

| ====== evt-backup.vbs=========

| if wscript.arguments.count < 1 then

| wscript.echo "Requires server name!"

| wscript.quit

| end if

|

| strComputer = wscript.arguments(0)

| If left(strComputer,2) <>"\\" then

| strComputer = "\\" & strComputer

| End if

|

| Set objWMIService = GetObject("winmgmts:" _

| & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

| & strComputer & "\root\cimv2")

| Set colLogFiles = objWMIService.ExecQuery _

| ("SELECT * FROM Win32_NTEventLogFile")

| For Each objLogfile in colLogFiles

| strBackupLog = objLogFile.BackupEventLog _

| ("c:\scripts\" & substr(strComputer,2) & objLogFile.LogFileName &

".evt")

| Next

|

|

|

| The main portion was gotten from the technet script center, but it is

| receiving errors:

|

| C:\Scripts\evt-backup.vbs(11, 1) (null): 0x80041021

|

| Line 11 begins with the "Set objWMIService"

|

| Thanks

| Carl

|

|









-

Re:copying event logs

You're welcome.



--

Regards,



Dave Patrick ....Please no email replies - reply in newsgroup.

Microsoft Certified Professional

Microsoft MVP [Windows]

www.microsoft.com/protect">www.microsoft.com/protect



"Carl Hilton" wrote:

| Thanks, I missed the original script adding the "\\".

|

| Carl





-

Re:copying event logs

While running the below script to take backup of remote systems, I am not

getting any backup....

I need to archive event logs on weekly basis using schedule task.



if wscript.arguments.count < 1 then

wscript.echo "Requires server name!"

wscript.quit

end if



Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

& strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _

("SELECT * FROM Win32_NTEventLogFile")

For Each objLogfile in colLogFiles

strBackupLog = objLogFile.BackupEventLog _

("c:\scripts\" & substr(strComputer,2) & objLogFile.LogFileName & ".evt")

Next

-

Re:copying event logs

nat wrote:

Quote
While running the below script to take backup of remote systems, I am not

getting any backup....

I need to archive event logs on weekly basis using schedule task.



if wscript.arguments.count < 1 then

wscript.echo "Requires server name!"

wscript.quit

end if



Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

& strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _

("SELECT * FROM Win32_NTEventLogFile")

For Each objLogfile in colLogFiles

strBackupLog = objLogFile.BackupEventLog _

("c:\scripts\" & substr(strComputer,2) & objLogFile.LogFileName & ".evt")

Next

Can we assume strComputer is passed as an argument? If the computername

has dashes I've found I've needed to enclose it in "". Are you getting

any error messages? Do you have On Error Resume Next commented out?



--

Jeffery Hicks

SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

VBScript & Windows PowerShell Training -

www.ScriptingTraining.com/classes.asp

Windows PowerShell? - www.SAPIENPress.com/powershell.asp



blog: blog.SAPIEN.com">blog.SAPIEN.com

blog: jdhitsolutions.blogspot.com">jdhitsolutions.blogspot.com

-