none
Get only selected columns and combine two output results RRS feed

  • Domanda

  • I am very very new to powershell

    Working on doing some automated patching in our SQL server environments.  I am first taking a DB backup and then applying patches and then sending output in an email

    I need to figure out two things:

    1.  How do I get  only few columns displayed in the output? for example the backup-dbadatabase gives me about 20 columns which I don't need
    2.  how do I get the results of second command in the email? when I run this script I only get the output of the first command in the email

    $Results = backup-dbadatabase -sqlinstance abcsqlserver -database 'abc' -path \\abcsqlserver\Backup -type full -copyonly -compressbackup -ignorefilecheck;update-dbainstance abcsqlserver -KB 4019094 -path \\abcsqlserver\Patches -restart -confirm:$false

    $to = 'abc@abc.com'

    $smtp = 'mailrelay.abc.local'

    $from = 'abc@abc.com'

    $subject = 'SQL Server Patching on abcsqlserver'

    $Body = $Results | convertto-html | Out-String

    Send-MailMessage -To $to -From $from -Body $Body -bodyashtml -Subject $subject -SmtpServer $smtp

     

    Any help is greatly appreciated

    Thanks

    martedì 28 gennaio 2020 16:54

Tutte le risposte

    1.  How do I get  only few columns displayed in the output? for example the backup-dbadatabase gives me about 20 columns which I don't need


    $Results | Format-Table -Wrap -Property $ColumnName2, $ColumnName5

    martedì 28 gennaio 2020 17:27
  • Format-Table won't work with ConvertTo-Html..

    help select-object -online


    \_(ツ)_/

    martedì 28 gennaio 2020 19:11
    Moderatore