none
how to log the powershellactivity RRS feed

  • Question

  • I am running a PS script to stop and restart Services using Restart-Service. For troubleshooting issues I'd like to write the output of every activity to a log file so we can make sure the services stopped and restart.please find the code:

    $logfile = 'c:\Temp\test.log'

    $mailprops= @{

    From = 'operating.system@abc.com'

    To = 'asdf@abc.com'

    Subject = 'test'

    Attachment = $logfileSmtpServer = '127.0.0.1'
    }

    'Stopping services' | Out-File $logfile

    Stop-Service '3456','2354' 'Services stopped' | Out-File $logfile -append

    Restart-computer QY34-Force 'Remote computer sent restart command' | Out-File $logfile -append

    Send-MailMessage @mailprops

    • Moved by Bill_Stewart Wednesday, September 4, 2019 8:49 PM Duplicate
    Sunday, April 7, 2019 1:42 AM

All replies