I made a PowerShell script today. It copies only the most recent file in one directory to another directory and e-mails me a simple status report. Let me show you the script…
gci c:source | sort LastWriteTime -desc | select -first 1 |cpi -dest c:destination -ea SilentlyContinue -ev copyerrif($copyerr.count -gt 0){$smtp = new-objectNet.Mail.SmtpClient("mail.myserver.com")$smtp.Send("My Name <my@email.com>","recipient@email.com", "Error copying file","Copy failed with the following error message: " + $copyerr)}else{$smtp = new-objectNet.Mail.SmtpClient("mail.myserver.com")$smtp.Send("My Name <my@email.com>","recipient@email.com", "File copied successfully", "Sweet.")}
…so this loaded script does a lot in the first line. It finds all the files in the source folder, sort's them by LastWriteTime, selects the first one, and copies that file to the desired location. Errors are logged in copyerr, and if any errors are found in copyerr then I get an e-mail saying that it didn't succeed. Otherwise I get an e-mail saying that it did.
My first useful powershell script! I think I like powershell.