none
Looking to import file names and send in e-mail RRS feed

  • Question

  • I have a somewhat idea but need a little direction on this script.
    I am trying to do the easiest possible solution for this.

    I have backup files that are in a specific folder that are being backed up from a database. I would like to setup a task to run a powershell script and then e-mail me the file names of the backups that are being created. This is mainly to ensure that backups are actually being ran and are working. I could have it send me the actual backup files but im sure this would be quite a big file if it sends multiple things. Maybe their is a easier way. Here is what I had it mind but dont know where to go from here.

    $dir = "C:\Users\Test\Backups"
    
    Get-ChildItem -Path $dir 

    Thursday, April 10, 2014 2:07 PM

Answers

All replies

  • Database backups can be configure to send status via email on success, failure or both.  Just check the maintenance task in the server and set it to send email.

    To send mail with PowerShell look into using this:

    HELP Send-MailMessage -full

    Is this a homework question?


    ¯\_(ツ)_/¯

    Thursday, April 10, 2014 2:18 PM
  • Hi,

    I'd do something along these lines to start with:

    $dir = 'C:\Users\Test\Backups'
    
    $body = Get-ChildItem $dir | Select Name,Length,LastWriteTime | Out-String
    
    Send-MailMessage -To you@domain.com -From dnr@domain.com -Subject 'Backup Report' -Body $body -SmtpServer smtp.domain.com


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    • Marked as answer by bohlingj Thursday, April 10, 2014 2:56 PM
    Thursday, April 10, 2014 2:18 PM
  • Nope this is just something I am looking to setup. I have noticed you (Jrv) and (Mike Laughlin) are always posting answers in these powershell forums. I appreciate all your hard work and dedication. I hope to learn PowerShell more so I can contribute as much as you both do.

    Thank you!

    Thursday, April 10, 2014 2:42 PM
  • Cheers, you're very welcome. I'm always glad to help out.

    I can honestly say that lurking in these forums helped me immensely when I was first learning PowerShell. The hardest part for me was coming up with ideas for things to learn. Hanging out here provides plenty of options.


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Thursday, April 10, 2014 2:57 PM
  • Nope this is just something I am looking to setup. I have noticed you (Jrv) and (Mike Laughlin) are always posting answers in these powershell forums. I appreciate all your hard work and dedication. I hope to learn PowerShell more so I can contribute as much as you both do.

    Thank you!

    The reason I ask is that I have been a consulting DBA for many decades.  We have had many issues of people in the little fiefdoms of an organization setting up sp3ecial little tests.  Many times this has led to conflicts and errors. One case is much like yours.

    A manager tasked a "help desk" person to email a daily report on the name and size of a SQL backup.  The HD persondutifully did as told.  In the organization there was a hard fast rule that anything to do with the databases must be worked through the identified system DBA.  This was not done.  Here is what happened.

    Our database backups exceeded storage capacity so we split them.  The new backups were moved to a direct to tape system using Seagate Backup.  As a result no files were being generated.  This led to the manager accusing the DBAs of failing to backup the data.  The DBAs were in a different division and just responded with "all backups are being done according to the currently defined practices".  This made the manager crazy and a war ensued which went on between departments and divisions for over a week.

    The end result was many people were embarrassed and a lot of time was wasted.  In the end the manager was added to the email notification list and was also admonished for trying to bypass procedures.

    Your attempt to validate backups by watching files is faulty and not the correct way to do this.  The backup system was designed to send notifications.  Ask you DBA or DB vendor to set up the email and add you to the distribution list.  Why reinvent the wheel.  It is not a technically correct approach.  Don't say corporate standards or your boss doesn't want that.  You are the tech.  Advise you manager of the correct technical solutions.


    ¯\_(ツ)_/¯

    Thursday, April 10, 2014 3:10 PM