Add more columns to output

  • $msg = Get-Content 'C:\miscjunk\SQL_Servers.txt' |
    ForEach-Object {New-Object 'Microsoft.SqlServer.Management.Smo.Server' $_} |
    Select-Object -Expand Databases |

    Select-Object Name,
    @{n='LastBackupDate';e={if ($_.LastBackupDate -eq '01/01/0001 00:00:00') {'NA'} else {$_.LastBackupDate}}}|
    #@{n='LastDifferentialBackupDate';e={if ($_.RecoveryModel -eq 'Simple' -or $_.LastDifferentialBackupDate -eq '01/01/0001 00:00:00') {'NA'} else {$_.LastDifferentialBackupDate}}}
    #@{n='LastLogBackupDate';e={if ($_.RecoveryModel -eq 'Simple' -or $_.LastLogBackupDate -eq '01/01/0001 00:00:00') {'NA'} else {$_.LastLogBackupDate}}} |
    ConvertTo-Html -Head $style | Out-String

    Send-MailMessage -From $emailFrom -To $emailTo -Subject $subject -Body $msg -BodyAsHtml -SmtpServer $smtpServer

    I would like to add which server, and results of backup success\failure, and run duration. Can this be incorporated with what I have .. what do I need to add?

    Thanks.

     

    • This topic was modified 1 year, 6 months ago by  Bruin.
  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • Any help on this request... I tried to goggle but didn't see examples...

    Thanks.

  • Bruin wrote:

    Any help on this request... I tried to goggle but didn't see examples...

    Thanks.

    I think the problem is that people doubt your claim.  Case in point...

    https://www.google.com/search?q=Get+backup+status+for+multiple+sql+servers+using+powershell

     

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I looked thru a lot of those articles and didn't see backup success\failure, and run duration within a P/S script.

    Thanks

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply