Parse log file using powershell

Hi,
Am pretty new to Powershell and would require anyone of your assistance in setting up a script which parse thru a log file and provide me output for my requirements below.
I would like to parse the Main log file for Barra Aegis application(shown below) using powershell.
Main log = C:\BARRALIN\barralin.log
Model specific log = C:\BARRALIN\log\WG*.log
Requirements :
1. scroll to the bottom of the log file and look for name called "GL Daily" and see the latest date which in the example log below is "20150203"
note : Name "GL Daily" and date keep changing in log file
2. Once entry is found i would like to have a check to see all 3 entries PREPROCESS, TRANSFER, POSTPROCESS are sucess.
3. If all 3 are success i would like to the script to identify the respective Model specific log number and print it out.
E.g if you see the sample log below for "GL Daily", it is preceded by number "1718" hence script should append the model log path with "WG00" along with 1718, finally it should look something like this  C:\BARRALIN\log\WG001718.log.
4. If all 3 items or anyone of them are in "failed" state then print the same log file info with WG001718.log
Any help on this would be much appreciated.
Thank You.
Main log file :
START BARRALINK            Check Auto Update                                                1716  
43006  20150203 
    Trgt/Arch c:\barralin                                               
    PREPROCESS           success   0 preprocessor: no error                   
    TRANSFER             success   1 Host success: files received             
    POSTPROCESS          success   0 Postprocessor: no error                  
    CONFIRMATION         success   2 No Confirm needed                        
STOP  43105  20150203 
START Aegis                GL Monthly                                                    
  1716   43117  20150203 
    Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
    PREPROCESS           success   0 preprocessor: no error                   
    TRANSFER             success   1 Host success: files received             
    POSTPROCESS          success   0 Postprocessor: no error                  
    CONFIRMATION         success   2 No Confirm needed                        
STOP  44435  20150203
START Aegis                UB Daily                                                    
  1717   43107  20150203 
    Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
    PREPROCESS           success   0 preprocessor: no error                   
    TRANSFER             success   1 Host success: files received             
    POSTPROCESS          success   0 Postprocessor: no error                  
    CONFIRMATION         success   2 No Confirm needed                        
STOP  44435  20150203 
START Aegis                GL Daily                                                    
    1718   44437  20150203 
    Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
    PREPROCESS           success   0 preprocessor: no error                   
    TRANSFER             success   1 Host success: files received             
    POSTPROCESS          success   0 Postprocessor: no error                  
    CONFIRMATION         success   2 No Confirm needed                        
STOP  50309  20150203 
 

Hi All,
I was writing a function in power shell to send email and i was looking to attach lines as and when required to the body of the email. but am not able to get this done..Here's my code
Function Email ()
$MailMessage = New-Object System.Net.Mail.MailMessage
$SMTPClient = New-Object System.Net.Mail.SmtpClient -ArgumentList "mailhost.xxx.com"
$Recipient = "[email protected]"
If ($MessageBody -ne $null)
$MessageBody = "The details of Barra $strsessionProduct model is listed below
`rHostName : $localhost
`r Model Run Date : $Date
`r Model Data Date : $DateList1
`r`n Click for full job log"+ "\\"+$localhost+"\E$\Local\Scripts\Logs "
$MailMessage.Body = $MessageBody
If ($Subject -ne $null) {
$MailMessage.Subject = $Subject
$Sender = "[email protected]"
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender
$MailMessage.to.Add($Recipient)
If ($AttachmentFile -ne $null) { $MailMessage.Attachments.add($AttachmentFile)}
$SMTPClient.Send($MailMessage)
$Subject = "Hello"
$AttachmentFile = ".\barralin.log"
$MessageBody = "Add this line to Body of email along with existing"
Email -Recipient "" -Subject $Subject -MessageBody $MessageBody -AttachmentFile $AttachmentFile
as you can see before calling Email function i did add some lines to $MessageBody and was expecting that it would print the lines for $MessageBody in Email Function along with the new line. But thats not the case.
I have tried to make $MessageBody as an Array and then add contents to array
$MessageBody += "Add this line to Body of email along with existing"
$MessageBody = $MessageBody | out-string
Even this didnt work for me. Please suggest me any other means to get this done.
THank You

Similar Messages

  • Parsing Log file with PowerShell

    Hey Guys, I have the following line in a txt file (log file) 
    2012-08-14 18:00:00 [ERROR] . Exception SQL error 1 2012-08-14 18:10:00 [ERROR] . Exception SQL error 22012-08-15 18:00:00 [INFO] . Started 
    - Check the most recent entry(s) the last 24 hours
    - if there's an error [ERROR] write-out a statement that says (Critical) with the date-time of the error
    - If there's no erros write-out (Ok)
    So far I learned to write this much and would like to learn more from you:
    $file = "C:\Users\example\Documents\Log.txt" cat $file | Select-String "ERROR" -SimpleMatch

    Hello,
    I am new to PowerShell, and looking for same requirement, here is my function.
    Function CheckLogs()
        param ([string] $logfile)
        if(!$logfile) {write-host "Usage: ""<Log file path>"""; exit}
        cat $logfile | Select-String "ERROR" -SimpleMatch | select -expand line |
             foreach {
                        $_ -match '(.+)\s\[(ERROR)\]\s(.+)'| Out-Null 
                        new-object psobject -Property @{Timestamp = [datetime]$matches[1];Error = $matches[2]} |
                        where {$_.timestamp -gt (get-date).AddDays(-1)}
                        $error_time = [datetime]($matches[1])
                        if ($error_time -gt (Get-Date).AddDays(-1) )
                            write-output "CRITICAL: There is an error in the log file $logfile around 
                                          $($error_time.ToShortTimeString())"; exit(2)
      write-output "OK: There was no errors in the past 24 hours." 
    CheckLogs "C:\Log.txt" #Function Call
    Content of my log file is as follows
    [ERROR] 2013-12-23 19:46:32
    [ERROR] 2013-12-24 19:46:35
    [ERROR] 2013-12-24 19:48:56
    [ERROR] 2013-12-24 20:13:07
    After executing above script, getting the below error, can you please correct me.
     $error_time = [datetime]($matches[1])
    +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray
    Cannot index into a null array.
    At C:\PS\LogTest.ps1:10 char:21
    +                     new-object psobject -Property @{Timestamp = 
    [datetime]$match ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray
    Cannot index into a null array.
    At C:\Test\LogTest.ps1:12 char:21
    +                     $error_time = [datetime]($matches[1])
    +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

  • Parsing text file using powershell

    Hi
    I am trying to extract
    ONLY the IP addresses in a DNS log file.  There are different IP addresses in the file. I managed to extract some data but that depends on the pattern that I am supplying, see command below
    Select-String -Path .\dns.log "snd*" | %{$_.line.split()} | Select-String "192.*"| Select-Object -Unique
    Select-String -Path .\dns.log "snd*" | %{$_.line.split()} | Select-String "10.*"| Select-Object -Unique
    any help would be appreciated
    mjksgea

    Hi
    there is an error with the word path.  removing it and running the script i get nothing, so I presume the $pattern needs changing, I am not familair with regex.
    A sample of the file
    09/04/2015 16:45:46 0574 PACKET  00000000055FFC60 UDP Rcv 10.10.30.21    f37b   Q [0001   D   NOERROR] A      (8)servername(5)Xsomthing(2)somthing(2)com(0)
    regards

  • How to get Document Set property values in a SharePoint library in to a CSV file using Powershell

    Hi,
    How to get Document Set property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi,
    According to your description, my understanding is that you want to you want to get document set property value in a SharePoint library and then export into a CSV file using PowerShell.
    I suggest you can get the document sets properties like the PowerShell Command below:
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $siteurl="http://sp2013sps/sites/test"
    $listname="Documents"
    $mysite=new-object microsoft.sharepoint.spsite($siteurl)
    $myweb=$mysite.openweb()
    $list=$myweb.lists[$listname]
    foreach($item in $list.items)
    if($item.contenttype.name -eq "Document Set")
    if($item.folder.itemcount -eq 0)
    write-host $item.title
    Then you can use Export-Csv PowerShell Command to export to a CSV file.
    More information:
    Powershell for document sets
    How to export data to CSV in PowerShell?
    Using the Export-Csv Cmdlet
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Display data in log file using PL/SQL procedure

    Just as srw.message is used in Oracle RDF Reports to display data in log file in Oracle Apps, similarly how it is possible to display data in log file using PL/SQL procedure?
    Please also mention the syntax too.

    Pl post details of OS, database and EBS versions.
    You will need to invoke the seeded FND_LOG procedure - see previous discussions on this topic
    Enable debug for pl/sql
    https://forums.oracle.com/forums/search.jspa?threadID=&q=FND_LOG&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    HTH
    Srini

  • How to write to log files using java files from JSP

    Anybody knows different options in writing to log files using JSP?

    Do you have an example?in the init() method of the servlet put the following
            FileOutputStream out = new FileOutputStream("your-log-file");
            PrintStream ps = new PrintStream(out);
            System.setOut(ps);
            System.setErr(ps);load the servlet on startup using <load-on-startup> in web.xml

  • Report the size of all SharePoint Databases in a text file using PowerShell?

    I am new to Powershell. please help me for following question with step by step process.
    How to report the size of all SharePoint Databases in a text file using PowerShell?

    Hi Paul,
    Here is the changed script, which will also include the size for the Config DB.
    Please let me know if it worked:
    #Get SharePoint Content database sizes
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    $date = Get-Date -Format "dd-MM-yyyy"
    #Variables that you can change to fit your environment
    $TXTFile = "D:\Reports\SPContentDatabase_$date.txt"
    $SMTPServer = "yourmailserver"
    $emailFrom = "[email protected]"
    $emailTo = "[email protected]"
    $subject = "Content & Config Database size reports"
    $emailBody = "Daily/Weekly/Monthly report on Content & Config databases"
    $webapps = Get-SPWebApplication
    $configDB = Get-SPDatabase | ?{$_.Name -eq ((Get-SPFarm).Name)}
    $ConfigDBSize = [Math]::Round(($configDB.disksizerequired/1GB),2)
    Add-Content -Path $TXTFile -Value "Config Database size: $($ConfigDBSize)GB"
    Add-Content -Path $TXTFile -Value ""
    foreach($webapp in $webapps)
    $ContentDatabases = $webapp.ContentDatabases
    Add-Content -Path $TXTFile -Value "Content databases for $($webapp.url)"
    foreach($ContentDatabase in $ContentDatabases)
    $ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)
    Add-Content -Path $TXTFile -Value "- $($ContentDatabase.Name): $($ContentDatabaseSize)GB"
    if(!($SMTPServer) -OR !($emailFrom) -OR !($emailTo))
    Write-Host "No e-mail being sent, if you do want to send an e-mail, please enter the values for the following variables: $SMTPServer, $emailFrom and $emailTo."
    else
    Send-MailMessage -SmtpServer $SMTPServer -From $emailFrom -To $emailTo -Subject $subject -Body $emailBody -Attachment $TXTFile
    Nico Martens - MCTS, MCITP
    SharePoint 2010 Infrastructure Consultant / Trainer

  • How to get DocSet property values in a SharePoint library into a CSV file using Powershell

    Hi,
    How to get DocSet property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi AOK,
    Would you please post your current script and the issue for more effcient support.
    In addition, to manage document set in sharepoint please refer to this script to start:
    ### Load SharePoint SnapIn
    2.if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
    3.{
    4. Add-PSSnapin Microsoft.SharePoint.PowerShell
    5.}
    6.### Load SharePoint Object Model
    7.[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    8.
    9.### Get web and list
    10.$web = Get-SPWeb http://myweb
    11.$list = $web.Lists["List with Document Sets"]
    12.
    13.### Get Document Set Content Type from list
    14.$cType = $list.ContentTypes["Document Set Content Type Name"]
    15.
    16.### Create Document Set Properties Hashtable
    17.[Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
    18.$docsetProperties = @{"CustomColumn1"="Value 1"}
    19.$docsetProperties = @{"CustomColum2"="Value2"}
    20. ### Add all your Columns for your Document Set
    21.
    22.### Create new Document Set
    23.$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
    24.$web.Dispose()
    http://www.letssharepoint.com/2011/06/document-sets-und-powershell.html
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Removing non printable characters from an excel file using powershell

    Hello,
    anyone know how to remove non printable characters from an excel file using powershell?
    thanks,
    jose.

    To add - Excel is a binary file.  It cannot be managed via external methods easily.  You can write a macro that can do this.  Post in the Excel forum and explain what you are seeing and get the MVPs there to show you how to use the macro facility
    to edit cells.  Outside of cell text "unprintable" characters are a normal part of Excel.
    ¯\_(ツ)_/¯

  • Merge xls files using powershell

    is there any way to merge xls files using powershell ?

    What does "merge" mean?  Copy cells?  Copy Sheets?  Copy formulas?  Copy Data?
    "Merge"is way too vague.
    ¯\_(ツ)_/¯

  • Is it possible to monitor State change of a .CSV file using powershell scripting ?

    Hi All,
    I just would like to know Is it possible to monitor State change of a .CSV file using powershell scripting ? We have SCOM tool which has that capability but there are some drawbacks in that for which we are not able to utilise that. So i would like
    to know is this possible using powershell.
    So if there is any number above 303 in the .CSV file then i need a email alert / notification for the same.
    Gautam.75801

    Hi Jrv,
    Thank you very much. I modified the above and it worked.
    Import-Csv C:\SCOM_Tasks\GCC2010Capacitymanagement\CapacityMgntData.csv | ?{$_.Mailboxes -gt 303} | Export-csv -path C:\SCOM_Tasks\Mbx_Above303.csv;
    Send-MailMessage -Attachments "C:\SCOM_Tasks\Mbx_Above303.csv" -To “[email protected]" -From “abc@xyz" -SMTPServer [email protected] -Subject “Mailboxex are above 303 in Exchange databases” -Body “Mailboxex are above 303 in Exchange databases" 
    Mailboxex - is the line which i want to monitor if the values there are above 303. And it will extract the lines with all above 303 to another CSV file and 2nd is a mail script to email me the same with the attachment of the 2nd extract.
    Gautam.75801

  • How can I log BT device IDs names in a log file using Toshiba BT stack

    Hi,
    without Microsoft stack I can't use a lot of freeware programs (BluetoothView.exe, BluetoothCL.exe, BTScanner for Windows) to "catch" bluetooth devices in a log file.
    How can I log bt device ids/description names in a log file using Toshiba Bluetooth stack?
    Thank you

    I've just contacted Toshiba here:
    http://aps2.toshiba-tro.de/bluetooth/?page=faq/sdk
    There are other solutions for Windows XP or Toshiba SDK is the only one?

  • Can I monitor a Log file using EMGC 10.2.0.2?

    Hi,
    I am thinking of monitoring my web application log file using EMGC by creating a generic service is that possible. Now we are using some shell scripts to do that but its bit difficult to maintain all these shell scripts on each of the host. Is there any in built in mechanism that enable me to monitor the log file and when a perticular pattern match I would like to send a email notification to concerned people say application admins if there is no out of box option for this do we have plugins to do this. please let me know the possibility of implementing this using EMGC or extencibility plug-ins.
    Ashok Chava.

    Hi,
    I have used "Log File Pattern Matched Line Count" of host to monitor the log files and below is the pattern I have defined for the log file. But i could not find any alerts even there are so many such exceptions in the log file matching the patteren given in EMGC.
    /u01/app/oracle/product/IAS904/sysman/log/emias.log;%oracle.sysman.emSDK.util.jdk.EMException;%
    I have even add the log file in agent_home/sysman/config/lfm_ifiles file as given in the documentation but I could not see any alerts as expected am I doint anything wrong in my setup.
    Please let me know.
    Thanks,
    Ashok Chava

  • Unable to remove *.log files using utl_file.fremove

    Hi,
    I want to remove .log files using the below command
    I want to remvoe all the *.log files but its remvoing only one .log file
    utl_file.fremove(location => dir_name, filename => log_file_name);
    Any help will be needful for me

    In the documentation for your unknown version of oracle you can view the definition of utl_file.fremove.
    Everywhere it states utl_file.fremove removes a file, not 1 or more, and the documentation doesn't discuss the use of wildcards.
    It seems like the question could have been prevented by reading docs (which almost no one here does), and you need to use Java to address your requirement.
    Personally I wouldn't misuse Oracle to perform O/S tasks.
    Sybrand Bakker
    Senior Oracle DBA

  • Parsing .xfdl file using c#

    Hello All,
    I am developing app using c#. Can any one please help me how can I parsing .xfdl file using c#? Actually I want to read value from .xfdl file and show. how can I do this please help me.
    ThanQ
    Ganesh

    Hello All,
    I am developing app using c#. Can any one please help me how can I parsing .xfdl file using c#? Actually I want to read value from .xfdl file and show. how can I do this please help me.
    ThanQ
    Ganesh
    You'd better connect IBM for how to read xfdl file.
    remember make the reply as answer and vote the reply as helpful if it helps.

Maybe you are looking for

  • Skip first screen & ECC 6 syntax error

    Hi, I have program that is in ECC 6 giving syntax error   call transaction v_tcode using i_bdc options from i_options                                       messages into i_message                                       and skip first screen. I am gett

  • Sync problems while exporting

    Hi everyone-- I have one clip in my sequence where the audio was out of sync on the actual tape. In Final Cut, I was able to align it so that it matched up with the video. However, when I go to export, FCP realigns the video and audio how it was on t

  • Lost cash??????

    i put in a $15 gift card and had 11.20 left. went to florida for 5 days get back no money left. i owed nothing.any ideas to what happened

  • Difficulty with Digitally Signed Email

    I have been having trouble downloading and displaying email messages that are digitally signed. I have downloaded the required certificates and imported them onto the Pre, using the methods outlined both here and in the Pre documentation. I have conf

  • Task Privileges for Existing Users - Looking for a global update solution

    After some reading I understand that if you set the task privileges for the PUBLIC user in the Privileges section of Discoverer Administrator (10g), any new user created in the system will pick up the privileges you have assigned to the PUBLIC user.