locked
Create Activity Log RRS feed

  • Question

  • I run PS script. It does the job but create log file activity is not working. What changes require to generate log file with this script.

    $Logfile = "c:\automation\powershell\logs\$(gc env:computername).log"Get-ChildItem –Path "D:\SAPInvoicePDF" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-5))} | Remove-ItemFunction LogWrite{   Param ([string]$logstring)   Add-content $Logfile -value $logstring}

    


    MM

    Sunday, June 16, 2019 3:35 AM

All replies

  • Please post your script correctly.


    \_(ツ)_/

    Sunday, June 16, 2019 4:45 AM
    Moderator
  • $Logfile = "c:\automation\powershell\logs\$(gc env:computername).log"
    Get-ChildItem –Path "D:\SAPInvoicePDF" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-5))} | Remove-Item
    Function LogWrite
    {
       Param ([string]$logstring)

       Add-content $Logfile -value $logstring
    }


    MM

    Sunday, June 16, 2019 5:43 AM
  • Please post your script correctly using the code posting tool.

    Since it is clear that you have no experience or knowledge of how to write a script I recommend that you start by learning basic PowerShell.  Once you have some basics you will be able to ask a question that makes sense.

    How to ask   questions in a technical forum

    Microsoft Virtual     Academy - Getting Started with Microsoft PowerShell

    You cannot just copy and paste code that you have found with no understanding of what the code does or how a script works. 

    Just pasting a function does not make it work.


    \_(ツ)_/

    Sunday, June 16, 2019 6:06 AM
    Moderator
  • If you do not understand what I am asking. You should not reply.

    MM

    Sunday, June 16, 2019 6:55 AM
  • If you do not understand what I am asking. You should not reply.

    MM

    If you cannot ask a correct question or you have no experience in scripting you will need to learn PowerShell and think about what you are trying to ask.

    Please read the links I posted.  We cannot teach you PowerShell or how to script.  We cannot decode vague questions.  Please take the time to think about what you are trying to ask.

    The easiest way to create a log is to use the transcript utility.

    help start-transcript -online


    \_(ツ)_/


    Sunday, June 16, 2019 6:59 AM
    Moderator
  • Microsoft has the quantity but not quality any more on this forum. If I learn PS I will not be posting here.

    MM

    Sunday, June 16, 2019 7:04 AM
  • That seems to be the issue.  You must learn basic technology before understanding how to ask a question,  The links will teach you the fundamentals.  If you can't learn for some reason then you can post in the Forum for Script requests and someone will write a script for you.  You can also contact a consultant to do this for you.  The forum is not for asking for others to write a script for you and posting some odd things pasted together does not count as a script.

    Also note that this is a moderated community forum. It is not Microsoft support. 

    How to ask   questions in a technical forum


    \_(ツ)_/

    Sunday, June 16, 2019 7:11 AM
    Moderator
  • Can u delete this post?

    MM

    Sunday, June 16, 2019 7:47 AM
  • Why?  The information will be useful to others - or - you could try to ask a question after reading the links and gaining some basic understanding of scripting.

    There are at least three main issues with you code that show it has never worked or been tested.  You are also asking how to log "activity" but fail to say what activity you want to log.

    I recommend that, at a minimum, you learn how to use "help" and run help for each CmdLet you have copied.  That will give you some idea of what is wrong.

    You can also use the "-verbose" argument to get detailed output.

    To understand this just take the time to view the tutorial..  It will get you started in PowerShell and help you to ask a good question.


    \_(ツ)_/

    Sunday, June 16, 2019 7:53 AM
    Moderator
  • I have created script myself. there is no need for this post. Also the script I posted has conf data should be deleted.

    MM

    Sunday, June 16, 2019 8:27 AM