January 27, 2020 at 9:38 pm
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:
$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
January 28, 2020 at 6:32 pm
In reference to your first question, you can pipe the output and use select (select-object) to select the columns. If you were just doing the backup with something like $Results = backup-dbadatabase -sqlinstance etc then you can select the columns from $Results like:
$Results | select sqlinstance, Database, Start
In terms of multiple commands, if subsequent result sets contain different column lists than the first, those result sets are not displayed. I haven't played with the update-dbainstance but I would guess that is the issue. Try using different two different variables for results for the two different commands.
Sue
January 28, 2020 at 7:47 pm
Thank you I got the first one working. Still trying to figure out the multiple outputs one.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy