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