Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Moving files and getting results

$
0
0

I'm new to powershell and am writing my first script. So far what I've got is working like I need it to but I want to improve on it. Right now I've got files that are created everyday and I want to be able to move those daily files into a directory that is created by date and then email me the results. This script does that but what I would like it to do is to be able to do some error checking, some averages and then email me those results in a email not just as an attachment.

bjrep = "C:\script"
$bjftp = "C:\script\Outlist\450"
New-Item -ItemType Directory -Path "$bjrep\$((Get-Date).ToString('yyyy-MM-dd'))"
Move-Item -Path "$bjrep\*.txt" -Destination "$bjrep\$((Get-Date).ToString('yyyy-MM-dd'))"
Get-ChildItem -Path "$bjrep\$((Get-Date).ToString('yyyy-MM-dd'))" | Out-File "$bjftp\Script_Results_$((Get-Date).ToString('yyyy-MM-dd')).txt"
Send-MailMessage -To "me@domain.com" -subject "Script Results" -From "moveprocess@domain.com" -Body "Check the attachment to be sure files were copied" -Attachments "$bjftp\Script_Results_$((Get-Date).ToString('yyyy-MM-dd')).txt" -SmtpServer "email.domain.local"

What I would like is the results of that Get-ChildItem to be inserted into the body of the email message and also created as that file as its doing. I would also like this script to be able to look at the previous move operations directories and average out the number of files in those directories and if my script says that the daily average is 50 files and then all of the sudden there are 20 then alert me that something is off. I'm thinking I could use the Get-ChildItem along with the Measure-Object -average to accomplish this but am a little unsure of how to proceed.


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>