none
Write logfile of certain entries of script + only errors in logfile + send mail? RRS feed

  • Question

  • Hi,

    I have this script which deploys software. I'd like it to write a general logfile of who used it, timestamp and what the main results were (these thing already happen with write-host: f.e. "creating application x", "creating collections x,y,z") + log extensively only if errors occur + send a mail at the end of the exection.

    I could use this to log the output centrally, but how to add the user which executed it and the timestamp in a nice formatted way so I can easily find who deployed what on which date (for reference)?
    Then also I'd like to have a mail once there is an execution, so I know right away but it should only contain the actual execution, not the full logfile (for which I do have a function to send it to me)

    $Logfile = "D:\Apps\Logs\$(gc env:computername).log"
    
    Function LogWrite
    {
       Param ([string]$logstring)
    
       Add-content $Logfile -value $logstring
    }

    Please advise.
    J.


    Jan Hoedt

    Thursday, October 8, 2015 6:08 PM

Answers

  • $env:username

    [datetime]::now

    If you are asking for someone to write a script for you then you are in the wrong forum.


    \_(ツ)_/

    • Marked as answer by janhoedt Friday, October 9, 2015 8:54 AM
    Thursday, October 8, 2015 11:09 PM

All replies

  • $env:username

    [datetime]::now

    If you are asking for someone to write a script for you then you are in the wrong forum.


    \_(ツ)_/

    • Marked as answer by janhoedt Friday, October 9, 2015 8:54 AM
    Thursday, October 8, 2015 11:09 PM
  • Thanks for the first 2 lines, really appreciate it.

    About the 3rd one: why always that negative approach? You made your point of view really really really clear before several times.


    Jan Hoedt

    Thursday, October 8, 2015 11:51 PM
  • Thanks for the first 2 lines, really appreciate it.

    About the 3rd one: why always that negative approach? You made your point of view really really really clear before several times.


    Jan Hoedt

    Sorry. It just seems that you keep asking questions that you should know the answer to if you were trained in basic Windows and PowerShell. You cannot just keep asking for people to give you one line at a time to build your script.

    Jan - a little reading over this weekend would save you a lot of pain.

    image             
    Windows PowerShell 4.0 Examples              
    PDF             
    image             
    Windows PowerShell Integrated Scripting Environment 4.0              
    PDF             
    image             
    Windows PowerShell 4.0 Language Quick Reference              
    PDF             
    image             
    Windows PowerShell Desired State Configuration Overview              
    PDF
    imageSecrets of PowerShell Remoting             
    DOCX             
    Save As PDF Avail
    imageMaking Historical and Trend Reports in PowerShell             
    DOCX             
    Save As PDF Avail
    imageCreating HTML Reports in PowerShell             
    DOCX             
    Save As PDF Avail
    imageThe Big Book of PowerShell Error Handling             
    DOCX             
    Save As PDF Avail
    image             
    The Big Book of PowerShell Gotchas              
    DOCX             
    Save As PDF Avail
    imageThe Community Book of PowerShell Practices             
    DOCX             
    Save As PDF Avail
    image             
    The DSC Book              
    DOCX             
    Save As PDF Avail
    imageWindows PowerShell Networking Guide             
    DOCX             
    Save As PDF Avail

    image             
    Windows PowerShell Web Access Quick .Reference              
    PDF

     

    Good luck and have a great weekend


    \_(ツ)_/


    • Edited by jrv Friday, October 9, 2015 4:36 AM
    Friday, October 9, 2015 4:29 AM
  • Thanks for that, downloaded the pdfs and am printing them right now. DOCX-es are not available though :-(
    Nice weekend to you to.

    Jan Hoedt

    Friday, October 9, 2015 8:54 AM