Welcome to Scripting Forums Sign in | Join | Help
in Search

strComputer=*.*

Last post 10-11-2007, 1:38 PM by jeffthatcher. 2 replies.
Sort Posts: Previous Next
  •  10-09-2007, 12:51 PM 28624

    strComputer=*.*

    I am trying to find a vbscript that will backup and clear event logs on remote computers. What I am wondering is, can the strComputer function call the contents of a text file that say, has all the computers listed in it and then backup and clear the event logs for said computers?

     

    I found the script from Microsoft that allows one to backup and clear the event logs on a single computer, but being new to this I am not sure where to go next.

     

    This is the script that Microsoft and others have posted for backing up and clearing event logs. I have coupled this with dumpel.exe and have successfully parsed the security logs for the events I was intersted in, then backed up and cleared the logs.

    # Begin script 

    dtmThisDay = Day(Now)
    dtmThisMonth = Month(Now)
    dtmThisYear = Year(Now)
    strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate,(Backup,Security)}!\\" & _
     strComputer & "\root\cimv2")
    Set colLogFiles = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security'")
    For Each objLogfile in colLogFiles
     objLogFile.BackupEventLog("c:\scripts\" & strBackupName & _
    "_Security.evt")
     objLogFile.ClearEventLog()
    Next

    # End Script 

    Any help would be great!

  •  10-10-2007, 10:30 PM 28634 in reply to 28624

    Re: strComputer=*.*

    Hi Jeff,

    The WMI moniker string (the argument to the GetObject function in your code) only connects to a single computer. However, here are two options:

    1. Use the Cmd.exe For command to parse the text file and execute the WSH script for each line in the text file (simpler), or
    2. Extend the script to use the FileSystemObject objects and methods to read the text file from within the WSH script (more complex).

    For a quick-and-dirty solution, #1 is simpler. For example:

    @echo off
    setlocal enableextensions
    for /f %%p in ('type Computers.txt') do cscript MyScript.vbs %%p
    endlocal

    The above script echoes each line of the file Computers.txt and passes it as an argument to MyScript.vbs (your WMI script, above).

    Solution #2 is beyond the scope of a short forum reply, but there are numerous examples in past articles of how to open, read, and close text files from a WSH script. 

    HTH,

    Bill

  •  10-11-2007, 1:38 PM 28640 in reply to 28634

    Re: strComputer=*.*

    Thank you very much
View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Download Data Protection Manager 2007Disaster recovery at a low cost Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Microsoft Learning Snack - Green IT Through Virtualization Many organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. Order Your Fundamentals CD Today!Register today for your in-depth copy of one of three Fundamental CDs on the following topics – Exchange, SQL, and SharePoint. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Empower Your Processes with PowerShell 201Paul Robichaux delves deep into PowerShell how-tos in 3 informative lessons, each followed by live Q&A—all on your own computer! Register today! Microsoft Learning Snack - Green IT Through VirtualizationMany organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. New Release: Windows IT Pro Master CD13 years of content archives, fast answers with advanced search tools, and full access to WindowsITPro.com—order today!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing