none
Run a script that works for one .ALM-file, over several .ALM-files and add the results RRS feed

  • Question

  • Hello

    This script works for the textfile called A.ALM:

    $alarmList = @(Get-Content -Path '.\A.ALM') | foreach { 
    $token = $_ -split ' +'
    [PSCustomObject]@{
         date = $token[0]
         time = $token[1]
         H2   = $token[2]
         H3   = $token[3]
         H4   = $token[4]
         H5   = $token[5]
         H6   = $token[6]
         H7   = $token[7]
         H8   = $token[8]
    }
    }
    $alarmList | Group H4 -NoElement | Select Name,Count | Out-Gridview

    All data files look similar to this:

    2018-05-19  00:26:00,551 [XXX  ] D_TA204_GT1_DV_AL             CFN              LARM      D_TA204_GT1_Reglerfel                  
    2018-05-19  00:28:01,049 [XXX  ] D_TA204_GT41_DV_AL            CFN              LARM      D_TA204_GT41_Reglerfel                 
    2018-05-19  00:28:01,049 [XXX  ] D_TA204_GT31_DV_AL            CFN              LARM      D_TA204_GT31_Reglerfel                 
    2018-05-19  00:28:01,049 [XXX  ] D_TA204_GT21_DV_AL            CFN              LARM      D_TA204_GT21_Reglerfel                 
    2018-05-19  00:35:19,627 [XXX  ] U_TA364_GT11_LARM             CFN              LARM      U_TA364_GT11_LARM                      

    It gives me the count result for each unique alarm text. Next step is to run this script over all .ALM-files in a folder. I have come this far but am struggling with syntax and function.

    foreach ($i in Get-ChildItem .\) {$alarmList = @(Get-Content -Path $i)} |  
    foreach { 
        $token = $_ -split ' +'
        [PSCustomObject]@{
             date = $token[0]
             time = $token[1]
             H2   = $token[2]
             H3   = $token[3]
             H4   = $token[4]
             H5   = $token[5]
             H6   = $token[6]
             H7   = $token[7]
             H8   = $token[8]
        }
    }
    $alarmList | Group H4 -NoElement | Select Name,Count | Out-File $.txt

    In the first step i want the script to create a txt-file for each alm-file and print out the count result. When i manage and understand that i will try to add it all up into one text-file.

    Edit/Update:

    With help from an answer by @Kazun in this thread (not allowed to link)
    How to combine all text files inside a folder into one file, including subfolders

    i managed to first merge all my files, then run the single script. Am now working on naming appended file and the results-file after the newest date contained in the first token... Any improvements or suggestions would be appreciated.

    Cheers // DB



    • Edited by DBETT23 Wednesday, September 12, 2018 10:21 AM
    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:42 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, September 11, 2018 11:08 AM