Catch the error in to a log file

Hi Team,
Created the script for testing the server online or offline, Could you please tell me how to catch the error in to a file
Try
$Result = Test-Connection -count 1 -computer (Get-Content ServerName.txt)  -ErrorAction "Continue"
Catch
   $Result = New-Object PSCustomObject -Property @{
            TimeStamp = Get-Date
            __Server = $env:COMPUTERNAME
            Address = $Computer
            Protocol = ""
            ResponseTime = "Failed"
$Result | Select TimeStamp,__Server,Address,ProtocolAddress,ResponseTime | ft -AutoSize

As mjolinor pointed, you should change the -ErrorAction to Stop to make the control flow into catch block when error occurs. Just change alone is not sufficient because, the control will go to catch block if any of the computer in servername.txt gives error,
and it will not go back to next computer in your text file perform the ping.
So try chaning the code as shown below.
$Outarr = @()
foreach($Comp in (Get-Content C:\temp\servers.txt)) {
Try {
$Result = Test-Connection -count 1 -computer $Comp -ErrorAction stop
Catch {
$Result = New-Object PSCustomObject -Property @{
TimeStamp = Get-Date
__Server = $env:COMPUTERNAME
Address = $Comp
Protocol = ""
ResponseTime = "Failed"
$Outarr +=$Result
$Outarr| Select TimeStamp,__Server,Address,ProtocolAddress,ResponseTime | ft -AutoSize
Hope this helps.
Thanks,
Sitaram Pamarthi
Blog : http://techibee.com
Follow on Twitter
This posting is provided AS IS with no warranties or gurentees,and confers no rights
You can simplify that to:
$Outarr =
foreach($Comp in (Get-Content C:\temp\servers.txt)) {
Try {
Test-Connection -count 1 -computer $Comp -ErrorAction stop
Catch {
[PSCustomObject]@{
TimeStamp = Get-Date
__Server = $env:COMPUTERNAME
Address = $Comp
Protocol = ""
ResponseTime = "Failed"
$Outarr | ft -AutoSize
The [PSCustomObject] type accelerator will take the hash table as a constructor, and coerce it to an [ordered] hash table, so the properties will stay in the same order they were declared.  That eliminates the need to use Select-Object afterward to
get them back into the right order.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • Help on printing error messages to a log file

    Hi, may I know whether is there any way to print the error messages to a log file? Thanks for your help!

    noobboy,
    Please refrain from crossposting all of your questions into multiple forums. You were asked to stop this the last time you did this as well. Please be more considerate in future.

  • Print a custom Error message in the XML bursting program's log file...

    Hi,
    I having this requirement, where i need to print a custom error message in the xml bursting program's log file.
    Actually i am having a report where i create invoices and then those invoices are emailed to the respective customers, now say if a customer has three contacts and there is only two valid email id's so what happens is bursting will be successful for two contacts whereas the third contact dosen't get any emails. when this happens i need to log a message in the bursting programs log file stating a custom message.
    Two things i want to know..
    1- Whether is it possible to write into the xml bursting programs log file
    2- If yes, then how..
    note: it ll be greatly appreciated if the answer is elaborated.
    thanks,
    Ragul

    Hi,
    I having this requirement, where i need to print a custom error message in the xml bursting program's log file.
    Actually i am having a report where i create invoices and then those invoices are emailed to the respective customers, now say if a customer has three contacts and there is only two valid email id's so what happens is bursting will be successful for two contacts whereas the third contact dosen't get any emails. when this happens i need to log a message in the bursting programs log file stating a custom message.
    Two things i want to know..
    1- Whether is it possible to write into the xml bursting programs log file
    2- If yes, then how..
    note: it ll be greatly appreciated if the answer is elaborated.
    thanks,
    Ragul

  • How can we a validate a CSV file in SSIS and log the error details in another CSV File by using Sript Task.

    How can we a  validate a CSV file in SSIS and log the error details in another CSV File by using Sript Task.

    Please see:
    http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis
    http://social.msdn.microsoft.com/Forums/en-US/01ce7e4b-5a33-454b-8056-d48341da5eb2/vb-script-to-write-variables-to-text-file

  • How to catch the error code thrown by Oracle client installation?

    Hi everyone,
    Recently, I'm writing a bat file to install Oracle 11g client for windows, I know the command line should be below, but how to find the error code it return? like the command line I want to run in Windows, the errorlevel will return 0 if the command line is pass, otherwise it will return no-zero:
    oui.exe -silent -waitforcompletion -nowait -force -responseFile ...\response\clientruntime.rsp
    BTW, I know I can find the error info under the path ...\Oracle\Inventory\logs, but I think it is better if you can tell me another way to catch the error in command line. I just wish that I can determine whether the Oracle provider installation is pass......
    Thanks
    Lindsay
    Edited by: lindsaywang on Oct 6, 2008 1:28 PM

    I got it.
    Thanks,
    TD

  • How to catch the error occurred in Integration Process, and then save it?

    1. how to catch the error occurred in Integration Process, and then save the detailed error message to the file?
    2. there are fault message type for inbound message interface, how to use the fault message type in IR?
    Thanks,
    Michael
    Message was edited by: Spring Tang
    inital
    Message was edited by: Spring Tang
    detailed message output
    Message was edited by: Spring Tang
    fault message type

    Hi Spring,
    If u give an exception step along with your Transformation Step, whenever some error occurs in your message mapping, this exception block wil be triggered.
    You can configure your exception block to do all exception processing that you want. This exception handling is like any other java Exceptio n Handler. You can do anything that you want in your exception handler block on the basis of your requirements.
    <i>If an exception is triggered at runtime, the system first searches for the relevant exception handler in surrounding blocks. If it does not find the correct exception handler, it continues the search in the next block in the block hierarchy.
    When the system finds the correct system handler, it stops all active steps in the block in which the exception handler is defined and then continues processing in the exception handler branch. Once the exception handler has finished processing, the process is continued after the block.
    If the system fails to find an exception handler, it terminates the integration process with an error.</i>
    Regards,
    Bhavesh

  • What is the purpose of standby redo log files

    Hi,
    What is the purpose of the standby redo log files in DR?
    what if the standby redo log files are created? or else not created?
    Please explain
    Thanks

    3.1.3 Configure a Standby Redo LogA standby redo log is required for the maximum protection and maximum availability modes and the LGWR ASYNC transport mode is recommended for all databases. Data Guard can recover and apply more redo data from a standby redo log than from archived redo log files alone.
    You should plan the standby redo log configuration and create all required log groups and group members when you create the standby database. For increased availability, consider multiplexing the standby redo log files, similar to the way that online redo log files are multiplexed.>
    Reference http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ps.htm#i1225703
    HTH
    Anand

  • Can I catch the error instead of the DUMP GETWA_NOT_ASSIGNED ???

    Hi:
    I have the following code:
      FIELD-SYMBOLS:  . is executed i got a dump GETWA_NOT_ASSIGNED.
    Can I catch the error instead of the dump ?
    Thank you
    Silvia

    see the following example to avoid DUMP
    PARAMETERS: p_file LIKE rlgrap-filename .
    DATA: v_file TYPE string.
    DATA: BEGIN OF itab OCCURS 0,
          name(23) TYPE  c,
          END OF itab.
    DATA: errormessage TYPE char50.
    v_file = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename            = v_file
        filetype            = 'ASC'
        has_field_separator = ' '
      TABLES
        data_tab            = itab.
    RECEIVE RESULTS FROM FUNCTION 'GUI_UPLOAD'
    EXCEPTIONS
       file_open_error               = 1
       file_read_error               = 2
       no_batch                      = 3
       gui_refuse_filetransfer       = 4
       invalid_type                  = 5
       no_authority                  = 6
       unknown_error                 = 7
       bad_data_format               = 8
       header_not_allowed            = 9
       separator_not_allowed         = 10
       header_too_long               = 11
       unknown_dp_error              = 12
       access_denied                 = 13
       dp_out_of_memory              = 14
       disk_full                     = 15
       dp_timeout                    = 16
       OTHERS                        = 17 .
    break developer.
    CASE sy-subrc.
      WHEN 0.
        errormessage     = 'Data Loaded'.
      WHEN 1.
        errormessage     = 'FILE_OPEN_ERROR'.
      WHEN 2.
        errormessage     = 'FILE_READ_ERROR'.
      WHEN 3.
        errormessage     = 'NO_BATCH'.
      WHEN 4.
        errormessage     = 'GUI_REFUSE_FILETRANSFER'.
      WHEN 5.
        errormessage     = 'INVALID_TYPE'.
      WHEN 6.
        errormessage     = 'NO_AUTHORITY'.
      WHEN 7.
        errormessage     = 'UNKNOWN_ERROR'.
      WHEN 8.
        errormessage     = 'BAD_DATA_FORMAT'.
      WHEN 9.
        errormessage     = 'HEADER_NOT_ALLOWED'.
      WHEN 10.
        errormessage     = 'SEPARATOR_NOT_ALLOWED'.
      WHEN 11.
        errormessage     = 'HEADER_TOO_LONG'.
      WHEN 12.
        errormessage     = 'UNKNOWN_DP_ERROR'.
      WHEN 13.
        errormessage     = 'ACCESS_DENIED'.
      WHEN 14.
        errormessage     = 'DP_OUT_OF_MEMORY'.
      WHEN 15.
        errormessage     = 'DISK_FULL'.
      WHEN 16.
        errormessage     = 'DP_TIMEOUT'.
      WHEN 17.
        errormessage     = 'OTHERS'.
    ENDCASE.
    MESSAGE e000(00) WITH errormessage .

  • How to catch the error if an RFC fails due to short dump

    Hi All,
      I was calling the RFC Function module in parallel processing depends on the number of work processors available. I am getting the return message from the Function module using the perform statement
       PERFORMING task_return ON END OF TASK
    But I am not able to catch the errors if the RFC has been terminated due to the dump or manually killing the RFC while running.
    I need how to handle the RFC if the call has been terminated due to the dump or system failure. Does the RFC return the sy-subrc at this time or can we able to catch the error in any other way.
    Thanks & regards,
    Vijay

    Hello Vijay,
    If you're calling RFC from outside SAP using the OCX-SAPFunctions-Library, then you can catch the dump or any other exception occuring in your SAP-Function.
    Assuming that, objRFCFunc is the RFC-Function you can get the Excepetion-Code through objRFCFunc.Exception.
    It returns a String. If the error was a dump, the String is "SYSTEM_FAILURE". If it is a "regular" Exception you'll get the Exceptioncode. E.g. "NO_DATA_FOUND".
    If you need any sample code e.g. VBA-code for use in Office-Applications, let me know.
    regards
    Sven

  • Can anybody explain the difference REDOLG vs ARCHIVE log files

    can anybody explain the difference REDOLG vs ARCHIVE log files?
    and the relation between redolog files and redolog buffers?
    thanx in advance

    Changes made to the database are recorded in the Redo log buffer. This Buffer contains Redo records or entries, which are a description of changes made to the database.
    The Redo Logs are critical in order to recover the database or to reconstruct data files and undo segments after a system crash or hardware failure.
    Each Oracle instance has only one log writer process (LGWR). The log writer operates in the background and writes all records from the Redo log buffer to the Redo log files. When the database operates in Archivelog mode, the redo logs are are archived before overwritten.

  • I'm wondering..why does the outermost exception always catch the error?

    hi
    why do sometimes (or everytime) i create a code which looks something like this..
    try{
        try{
              //some error here
        } catch (Exception e){
               System.out.println("got it here: " + e.getMessage();
    }catch (Exception e){
          System.out.println("got it here instead: " + e.getMessage();
    }it's always the outermost catch block caughts the error. In this example the line got it here instead: some error messageis displayed.
    I really thought for sure the inner exception is the one who should catch the error first, right? Furthermore they both catch the same thing (Exception).
    Any information is greatly appreciated. thanks

    No, you're wrong.I'm relieved to hear that. But why does my code always does what I mentioned above? here's my code (it's a partial code, actually. it takes too many lines to put all the codes here):
    void generatePIN(String Date){
              char currentCodeChar;
              int seeder=0, serialNumber=0000000;
              int currentNumberInt=0, nextNumber=0, currentCodeInt=0;
              String voucherSerial=null, PINnumber=null, currentNumber=null, currentCode=null, nextCode=null, currentSerial=null, nextSerial=null;
              int PIN1=0,PIN2=0;
              String query=null;
              PreparedStatement ps=null;
              ResultSet rs=null;
              try{
                   //this portion here is used for proper seeding random number
                   SecureRandom sr1 = SecureRandom.getInstance("SHA1PRNG");
                   seeder=sr1.nextInt();
                   if (seeder<0){
                        seeder=seeder*-1;
              }catch (Exception e){
                   System.out.println(e.getMessage());
                   System.exit(1);
              random = new Random(seeder);
              PIN1 = random.nextInt(89999999)+10000000;
              PIN2 = random.nextInt(89999999)+10000000;
              PINnumber = "" + PIN1 + PIN2;
              System.out.println("PIN number: " + PINnumber);
              //check serial number first before storing the pin & serial number in database
              //if serial number exist, regenerate the serial number
              try{
                   try{
                   query = "select * from data1";
                   ps = con.prepareStatement(query);     
                   rs = ps.executeQuery();
                             while (rs.next()){
                             currentSerial = rs.getString("SerialNo");
                   }catch (SQLException ex){
                        System.out.println("error here?" + ex.getMessage());
                   while (currentNumberInt<=9999999){
                        currentNumberInt++;                    
              }catch (Exception e){
                   JOptionPane.showMessageDialog(null,"Database error 1: " + e.getMessage());
                   return;
         }the database is empty. hence it returns an error when i tried getting some data from it. but i expected the error message should be:
    error here? some error message..instead of the
    Database error 1: some error message pop-up being displayed.
    Did i make any mistake in my code? I've spent hours on this..
    thanks for helping

  • HT201250 My time machine back has been working perfectly well until yesterday when it failed. The error message I get is Files can't be copied onto the backup disk because it appears to be read-only. How do I fix it?

    My time machine back has been working perfectly well until yesterday when it failed. The error message I get is Files can’t be copied onto the backup disk because it appears to be read-only. How do I fix it?

    Hello,
    http://pondini.org/TM/C6.html

  • Unable to catch the error pls help

    Hi all am trying from last two hours but strangely unable to catch the error inthe below procedure..
    Ignore what the functionality is but look at these steps in the procedure ;Look at these two steps below in the procedure....
    It goes wrong at this point......
    v_acct_nb := in_acct_gp_array(i).gp_dtl_array(j).account_id;
    SELECT DISTINCT account_id INTO v_acct_dim_nb FROM ats_ACCOUNT WHERE account_id = v_acct_nb ; ----> this throws exception that no rows found
    I can see that values are passed into v_acct_nb variable.... but the second statements returns exception saying no data found .
    But
    when i hard code the value returned in the variable in the second statement like below it works ....
    v_acct_nb := in_acct_gp_array(i).gp_dtl_array(j).account_id; /* say i received the value v_acct_nb =20 */
    SELECT DISTINCT account_id INTO v_acct_dim_nb FROM ats_ACCOUNT WHERE account_id = '20'; -----> this works
    whats the issue here ?
    CREATE OR REPLACE PROCEDURE add_appl_dummy2( in_usr_id VARCHAR2,in_acct_gp_array appl_acct_gp_array,v_status_message OUT VARCHAR2)
    IS
    v_usr_dim_nb INTEGER;
    v_acct_dim_nb  VARCHAR2(35);
    v_user_exception     EXCEPTION;
    v_account_exception     EXCEPTION;
    v_acct_in_othr_group_exception  EXCEPTION;
    v_grp_already_exist_exception  EXCEPTION;
    v_acct_nb  VARCHAR2(35);
    v_error_code         VARCHAR2(50);
    v_error_msg          VARCHAR2(50);
    v_dflt_appl_acct_gp_nm VARCHAR2(50);
    v_dflt_appl_acct_gp_id INTEGER;
    v_count NUMBER;
    BEGIN
            /* verify if the user is valid */
            BEGIN
                SELECT usr_id INTO v_usr_dim_nb FROM TSS_USR WHERE access_id =in_usr_id ;
                EXCEPTION WHEN NO_DATA_FOUND THEN
                  v_error_code := SQLCODE;
                  v_error_msg  := SQLERRM;
                RAISE v_user_exception; 
            END;
    DBMS_OUTPUT.PUT_LINE('1');
            FOR i IN in_acct_gp_array.FIRST.. in_acct_gp_array.LAST
            LOOP
                /* Verify if the user has already created an account group with the same name */
                BEGIN
                  SELECT COUNT(1) INTO v_count FROM RPT_ACCT_GP WHERE usr_id=v_usr_dim_nb AND appl_acct_gp_nm=in_acct_gp_array(i).appl_acct_gp_nm;
                  IF v_count >0 THEN
    DBMS_OUTPUT.PUT_LINE('2');
                      RAISE v_grp_already_exist_exception;
                  ELSE
    DBMS_OUTPUT.PUT_LINE('3');
                      NULL;
                  END IF;
                END;
    DBMS_OUTPUT.PUT_LINE('4');
                FOR j IN in_acct_gp_array(i).gp_dtl_array.FIRST..in_acct_gp_array(i).gp_dtl_array.LAST
                LOOP
                      *v_acct_nb := in_acct_gp_array(i).gp_dtl_array(j).account_id;*    
       *SELECT DISTINCT account_id INTO v_acct_dim_nb FROM ats_ACCOUNT WHERE account_id = v_acct_nb ;*
       IF v_acct_dim_nb IS NULL THEN
        DBMS_OUTPUT.PUT_LINE('is null');
       ELSE
                     DBMS_OUTPUT.PUT_LINE(v_acct_dim_nb); /* verify if the account number is valid */
                         DBMS_OUTPUT.PUT_LINE(v_acct_nb);
                         END IF;
             END LOOP;
        END LOOP;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('9');
    v_status_message:='SUCCESS';
    EXCEPTION
        WHEN v_user_exception THEN
             v_status_message:= 'Invalid user id :'||in_usr_id ||' '||v_error_code||' '||v_error_msg;
        WHEN v_grp_already_exist_exception THEN
             v_status_message:= 'Group with the same name already exists ';
        WHEN OTHERS THEN
             v_status_message:= SQLCODE||' '||SQLERRM;
    END;
    SELECT DISTINCT account_id  FROM ats_ACCOUNT WHERE account_id='000000400127032'

    Please remove this bug anyway:
        WHEN OTHERS THEN
             v_status_message:= SQLCODE||' '||SQLERRM;

  • The analysis of a Apache log file

    What will you recommend for the analysis of a Apache log file?

    Your favorite text-editor?
    Are you looking for some specific analysis? There surely are tools available for that.
    Can you be more specific in your question, please.
    cu
    Andreas

  • Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at http:// (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.

    Is this a webpage that contains a link to a flv file? Please post a link to the page and tell us which link(s) are the problem flv files or else post a link to the .flv file itself.
    Alternately, click on one of the sample FLV File links on this page and tell us exactly what happens:
    http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html
    It might also help if you post the exact error message, including the path to the flv file.
    '''Note:'''
    Depending on how you have Firefox set up, clicking on a FLV File link will either save the FLV file to your computer or Firefox may open it automatically in an external application right after downloading (Firefox may ask you first). Firefox itself can't play FLV files so you need a "helper" application (or a plugin for flv files, if ther is one. You can see if Firefox is already set up to download or open FLV files by going to Firefox Preferences and looking in the Applications list. Find the FLV file type in the list and, if the action is "Open with", it should show the application that can play FLV files (e.g., VLC Media Player or Perian). See [[Managing filetypes]] for more information.

Maybe you are looking for