SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Configuring Database Mail with Powershell and SMO


Configuring Database Mail with Powershell and SMO

Author
Message
bruce 1565
bruce 1565
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1014 Visits: 1053
Comments posted to this topic are about the item Configuring Database Mail with Powershell and SMO
k_v@telenet.be
k_v@telenet.be
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 219
Great Bruce


Another wizard I will never open again because I now have the perfect script to replace it!

I just added [cmdletbinding()] and the server name as a param.

Now working on a script to create operators.


thank you very much.


Klaas
bruce 1565
bruce 1565
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1014 Visits: 1053
Glad you liked it. Here's what I use for operators.

# Configure the SQL Agent to use dbMail and add operators .
$sqlSrvObject.JobServer.AgentMailType = 'DatabaseMail'
$sqlSrvObject.JobServer.DatabaseMailProfile = $yourProfileNameHere
$o = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Agent.Operator($sqlSrvObject.JobServer, 'YourOperatorNameYere')
$o.EmailAddress = 'mailTo@yourDomain.tld'
$o.Create()
# or
$o = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Agent.Operator($sqlSrvObject.JobServer, $operatorNameHere)
$o.EmailAddress = $yourMailToAddressHere
$o.Create()
$sqlSrvObject.JobServer.Alter()


I haven't parameterized either since I don't have to set up mail or add operators too often, usually just when doing a new install.
k_v@telenet.be
k_v@telenet.be
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 219
That 's much easier than I expected.

I found a T-sql script, but I prefer the Powershell way.
I added those 4 lines as Step 10 in the Database Mail setup script, since I always need the 'helpdesk' operator whenever I install database mail.

Thanks again!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search