{"id":1350,"date":"2020-04-21T12:00:54","date_gmt":"2020-04-21T17:00:54","guid":{"rendered":"http:\/\/www.sqlnuggets.com\/?p=1350"},"modified":"2020-04-21T12:58:51","modified_gmt":"2020-04-21T17:58:51","slug":"setting-up-database-mail-and-sql-agent-alerts-with-powershell","status":"publish","type":"post","link":"https:\/\/sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/","title":{"rendered":"Setting Up Database Mail And SQL Agent Alerts With PowerShell"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280-1024x340.png\" alt=\"\" class=\"wp-image-1351\" srcset=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280-1024x340.png 1024w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280-300x100.png 300w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280-768x255.png 768w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As a DBA, you need to know when there&#8217;s a problem on your SQL Servers.  And while I <strong>highly <\/strong>recommend you use a full-fledged monitoring system, there are also some things you can set up on your SQL Servers so that they will tell you when certain things go wrong.  This doesn&#8217;t replace a full monitoring system, but setting up the below alerts will give you notification when SQL Server encounters things like corruption or resource issues. <\/p>\n\n\n\n<p>Before we get into the code, I want to be very clear in saying that I did not originally write these scripts.  I scoured the Internet to find a few tutorials that had what I needed, and pieced them together to produce the following.  The original scripts can be found here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\"https:\/\/www.sqlservercentral.com\/articles\/configuring-database-mail-with-powershell-and-smo (opens in a new tab)\" href=\"https:\/\/www.sqlservercentral.com\/articles\/configuring-database-mail-with-powershell-and-smo\" target=\"_blank\">https:\/\/www.sqlservercentral.com\/articles\/configuring-database-mail-with-powershell-and-smo<\/a><\/li><li> <a href=\"https:\/\/www.itprotoday.com\/sql-server\/set-operators-and-alerts-powershell\">https:\/\/www.itprotoday.com\/sql-server\/set-operators-and-alerts-powershell<\/a> <\/li><li> <a href=\"https:\/\/docs.dbatools.io\/#New-DbaDbMailAccount\">https:\/\/docs.dbatools.io\/#New-DbaDbMailAccount<\/a> <\/li><li> <a href=\"https:\/\/docs.dbatools.io\/#New-DbaDbMailProfile\">https:\/\/docs.dbatools.io\/#New-DbaDbMailProfile<\/a> <\/li><\/ul>\n\n\n\n<p>Based off of the above tutorials and documentation, I have created the below PowerShell script that does the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Configure a SQL Server to enable Database Mail<\/li><li>Set up initial mail account<\/li><li>Set up initial mail profile<\/li><li>Configure the SQL Agent to use the mail profile<\/li><li>Create an Agent Operator<\/li><li>Set up alerts for Error Severities 17-25 (read about those <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/errors-events\/database-engine-error-severities?view=sql-server-2017\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\">here<\/a>)<\/li><li>Set up alerts for Corruption Errors 823, 824, 825, and 829 (read about those <a href=\"https:\/\/sqlsoldier.net\/wp\/sqlserver\/day10of31daysofdisasterrecoverymonitoringforcorruptionerror\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\">here<\/a>)<\/li><\/ul>\n\n\n<pre class=\"lang:ps decode:true  \">####\n#below code \"inspired\" by: https:\/\/www.sqlservercentral.com\/articles\/configuring-database-mail-with-powershell-and-smo\n####\ncls\n\n$SQLInstance = \"SQLServer.YourDomain.com\" #Use FQDN\n$MailAccount = \"AccountName\"\n$MailProfile = \"ProfileName\"\n$EmailAddress = \"your@email.com\" #email address SQL Server will send from\n$MailServer = \"mail.YourDomain.com\"\n$OperatorName = \"AgentOperatorName\"\n$AlertEmail = \"your@email.com\" # the email address the alerts will go to\n\n\n# Load the SMO assembly and create the server object, connecting to the server.\n[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null\n$server = New-Object 'Microsoft.SqlServer.Management.SMO.Server' ($SQLInstance)\n\n# Configure the SQL Server to enable Database Mail.\n$server.Configuration.DatabaseMailEnabled.ConfigValue = 1\n$server.Configuration.Alter()\n\n#Set up initial mail account\nNew-DbaDbMailAccount -SqlInstance $SQLInstance -Name $MailAccount -EmailAddress $EmailAddress -MailServer $MailServer -Force\n#set up initial mail profile\nNew-DbaDbMailProfile -SqlInstance $SQLInstance -Name $MailProfile -MailAccountName $MailAccount\n\n#Configure the SQL Agent to use the mail profile.\n$server.JobServer.AgentMailType = 'DatabaseMail'\n$server.JobServer.DatabaseMailProfile = $MailProfile\n$server.JobServer.Alter()\n\n####\n#below code \"inspired\" by: https:\/\/www.itprotoday.com\/sql-server\/set-operators-and-alerts-powershell\n####\n\n$op = $server.JobServer.Operators[$OperatorName]\n#if the specified operator does not already exist, create it\nif ($op.Count -eq 0) {\n$op = New-Object ('Microsoft.SqlServer.Management.Smo.Agent.Operator') ($server.JobServer,$OperatorName)\n$op.EmailAddress = $AlertEmail\n$op.Create()\n}\n\n#set severity levels we want alerts for\n$sev = 17..25\n$msg = 823,824,825,829\n\nforeach ($sv in $sev) {\n$nm = \"Error $sv Alert\"\n$a = $server.JobServer.Alerts[$nm]\n#if the specified operator does not already exist, create it\nif ($a.Count -eq 0) {\n$a = New-Object ('Microsoft.SqlServer.Management.Smo.Agent.Alert') ($server.JobServer, $nm)\n$a.Severity = $sv\n$a.IncludeEventDescription = 'NotifyEmail'\n$a.Create()\n$a.AddNotification($OperatorName, [Microsoft.SqlServer.Management.Smo.Agent.NotifyMethods]::NotifyEmail)\n$a.Alter()\nwrite-host \"$nm Created\"\n}\n}\n\nforeach ($ms in $msg) {\n$nm = \"Error $ms Alert\"\n$a = $server.JobServer.Alerts[$nm]\n#if the specified alert does not already exist, create it\nif ($a.Count -eq 0) {\n$a = New-Object ('Microsoft.SqlServer.Management.Smo.Agent.Alert') ($server.JobServer, $nm)\n$a.MessageID = $ms\n$a.IncludeEventDescription = 'NotifyEmail'\n$a.Create()\n$a.AddNotification($OperatorName, [Microsoft.SqlServer.Management.Smo.Agent.NotifyMethods]::NotifyEmail)\n$a.Alter()\nwrite-host \"$nm Created\"\n}\n}<\/pre>\n<p><\/p>\n\n\n<p>This script has quickly become part of our standard server build.  After setting up the parameters initially, all we now have to do is change the server name and run it, and all of our alerts are set up for us in a matter of a few seconds.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a DBA, you need to know when there&#8217;s a problem on your SQL Servers. And while I highly recommend you use a full-fledged monitoring system, there are also some &#8230;<\/p>\n","protected":false},"author":2,"featured_media":1351,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[68,62,20,50],"tags":[19,66,47],"class_list":["post-1350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-configurations","category-corruption","category-powershell","category-sql-agent","tag-database-mail","tag-dbatools","tag-sql-agent"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets\" \/>\n<meta property=\"og:description\" content=\"As a DBA, you need to know when there&#8217;s a problem on your SQL Servers. And while I highly recommend you use a full-fledged monitoring system, there are also some ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Nuggets\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-21T17:00:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-21T17:58:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"425\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eric Cobb\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cfgears\" \/>\n<meta name=\"twitter:site\" content=\"@sqlnugg\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eric Cobb\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/\"},\"author\":{\"name\":\"Eric Cobb\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/person\\\/210536254addbc1b9d2d95dc1448b38a\"},\"headline\":\"Setting Up Database Mail And SQL Agent Alerts With PowerShell\",\"datePublished\":\"2020-04-21T17:00:54+00:00\",\"dateModified\":\"2020-04-21T17:58:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/\"},\"wordCount\":280,\"commentCount\":2,\"publisher\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/banner-1165979_1280.png\",\"keywords\":[\"Database Mail\",\"dbatools\",\"SQL Agent\"],\"articleSection\":[\"Configurations\",\"Corruption\",\"PowerShell\",\"SQL Agent\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/\",\"url\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/\",\"name\":\"Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/banner-1165979_1280.png\",\"datePublished\":\"2020-04-21T17:00:54+00:00\",\"dateModified\":\"2020-04-21T17:58:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/banner-1165979_1280.png\",\"contentUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/banner-1165979_1280.png\",\"width\":1280,\"height\":425},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlnuggets.com\\\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting Up Database Mail And SQL Agent Alerts With PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#website\",\"url\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\",\"name\":\"SQL Nuggets\",\"description\":\"Nuggets Of SQL Server Knowledge\",\"publisher\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/www.sqlnuggets.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\",\"name\":\"SQL Nuggets\",\"url\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/website-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/website-logo.jpg\",\"width\":320,\"height\":54,\"caption\":\"SQL Nuggets\"},\"image\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/sqlnugg\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/ericcobb\\\/\"]},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/person\\\/210536254addbc1b9d2d95dc1448b38a\",\"name\":\"Eric Cobb\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"caption\":\"Eric Cobb\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/cfgears\"],\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/author\\\/eric-cobb\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets","og_description":"As a DBA, you need to know when there&#8217;s a problem on your SQL Servers. And while I highly recommend you use a full-fledged monitoring system, there are also some ...","og_url":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/","og_site_name":"SQL Nuggets","article_published_time":"2020-04-21T17:00:54+00:00","article_modified_time":"2020-04-21T17:58:51+00:00","og_image":[{"width":1280,"height":425,"url":"https:\/\/www.sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","type":"image\/png"}],"author":"Eric Cobb","twitter_card":"summary_large_image","twitter_creator":"@cfgears","twitter_site":"@sqlnugg","twitter_misc":{"Written by":"Eric Cobb","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#article","isPartOf":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/"},"author":{"name":"Eric Cobb","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/person\/210536254addbc1b9d2d95dc1448b38a"},"headline":"Setting Up Database Mail And SQL Agent Alerts With PowerShell","datePublished":"2020-04-21T17:00:54+00:00","dateModified":"2020-04-21T17:58:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/"},"wordCount":280,"commentCount":2,"publisher":{"@id":"http:\/\/www.sqlnuggets.com\/#organization"},"image":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","keywords":["Database Mail","dbatools","SQL Agent"],"articleSection":["Configurations","Corruption","PowerShell","SQL Agent"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/","url":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/","name":"Setting Up Database Mail And SQL Agent Alerts With PowerShell - SQL Nuggets","isPartOf":{"@id":"http:\/\/www.sqlnuggets.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","datePublished":"2020-04-21T17:00:54+00:00","dateModified":"2020-04-21T17:58:51+00:00","breadcrumb":{"@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#primaryimage","url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","contentUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","width":1280,"height":425},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlnuggets.com\/setting-up-database-mail-and-sql-agent-alerts-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.sqlnuggets.com\/"},{"@type":"ListItem","position":2,"name":"Setting Up Database Mail And SQL Agent Alerts With PowerShell"}]},{"@type":"WebSite","@id":"http:\/\/www.sqlnuggets.com\/#website","url":"http:\/\/www.sqlnuggets.com\/","name":"SQL Nuggets","description":"Nuggets Of SQL Server Knowledge","publisher":{"@id":"http:\/\/www.sqlnuggets.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.sqlnuggets.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/www.sqlnuggets.com\/#organization","name":"SQL Nuggets","url":"http:\/\/www.sqlnuggets.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/logo\/image\/","url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2023\/11\/website-logo.jpg","contentUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2023\/11\/website-logo.jpg","width":320,"height":54,"caption":"SQL Nuggets"},"image":{"@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/sqlnugg","https:\/\/www.linkedin.com\/in\/ericcobb\/"]},{"@type":"Person","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/person\/210536254addbc1b9d2d95dc1448b38a","name":"Eric Cobb","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","caption":"Eric Cobb"},"sameAs":["https:\/\/x.com\/cfgears"],"url":"https:\/\/sqlnuggets.com\/author\/eric-cobb\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2020\/04\/banner-1165979_1280.png","jetpack_shortlink":"https:\/\/wp.me\/pdyDvE-lM","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":870,"url":"https:\/\/sqlnuggets.com\/getting-started-with-the-dbatools-powershell-module\/","url_meta":{"origin":1350,"position":0},"title":"Getting Started With The dbatools PowerShell Module","author":"Eric Cobb","date":"September 20, 2018","format":false,"excerpt":"If you are looking for a super easy way to start using PowerShell to manage your SQL Servers, then the\u00a0dbatools PowerShell module is for you!\u00a0 For those that aren't familiar, dbatools is a\u00a0free\u00a0PowerShell module with over 400 SQL Server best practice, administration, development and migration commands included. I have to\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/sqlnuggets.com\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":887,"url":"https:\/\/sqlnuggets.com\/using-dbatools-powershell-module-to-configure-sql-server\/","url_meta":{"origin":1350,"position":1},"title":"Using dbatools PowerShell Module To Configure SQL Server","author":"Eric Cobb","date":"October 9, 2018","format":false,"excerpt":"The more I use\u00a0the\u00a0dbatools PowerShell module, the more I like it.\u00a0 It really is a solid set of scripts that allow you to easily manage your SQL Servers via PowerShell.\u00a0 If you are not familiar with dbatools, I recommend you head over to my previous post,\u00a0Getting Started With The dbatools\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/sqlnuggets.com\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":341,"url":"https:\/\/sqlnuggets.com\/calling-powershell-from-sql-agent-gives-syntax-error\/","url_meta":{"origin":1350,"position":2},"title":"Calling PowerShell From SQL Agent Gives Syntax Error","author":"Eric Cobb","date":"March 16, 2017","format":false,"excerpt":"One cool thing that you can do in\u00a0SQL Server that a lot of people don't know about is\u00a0run PowerShell code\u00a0from a SQL Agent job. \u00a0However, I recently ran into a problem when trying to schedule a SQL Agent job to run a PowerShell script. \u00a0The script is fairly simple, it\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/sqlnuggets.com\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1307,"url":"https:\/\/sqlnuggets.com\/disable-telemetry-on-multiple-sql-servers-with-powershell\/","url_meta":{"origin":1350,"position":3},"title":"Disable Telemetry On Multiple SQL Servers With PowerShell","author":"Eric Cobb","date":"February 18, 2020","format":false,"excerpt":"Starting with SQL Server 2016, when you install SQL Server it also installs the CEIP (Customer Experience Improvement Program) Services, also known at Telemetry. In previous versions of SQL Server this was optional, but as of SQL Server 2016 it is automatically installed and enabled by default. Now whether this\u2026","rel":"","context":"In &quot;Configurations&quot;","block_context":{"text":"Configurations","link":"https:\/\/sqlnuggets.com\/category\/configurations\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/02\/binoculars-431488_1280.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/02\/binoculars-431488_1280.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/02\/binoculars-431488_1280.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/02\/binoculars-431488_1280.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/02\/binoculars-431488_1280.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1049,"url":"https:\/\/sqlnuggets.com\/patching-multiple-sql-servers-with-powershell-and-dbatools\/","url_meta":{"origin":1350,"position":4},"title":"Patching Multiple SQL Servers With Powershell and dbatools","author":"Eric Cobb","date":"July 18, 2019","format":false,"excerpt":"Patching SQL Server can sometimes be a time consuming process, especially when you have multiple servers that need to be patched. Remoting in to each box to run through the update wizard is tedious, and if you have multiple patches to apply you're going to be spending a considerable chunk\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/sqlnuggets.com\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/07\/powershell4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1534,"url":"https:\/\/sqlnuggets.com\/setting-the-database-owner-compatibility-level-and-recovery-model-with-powershell\/","url_meta":{"origin":1350,"position":5},"title":"Setting The Database Owner, Compatibility Level, And Recovery Model With PowerShell","author":"Eric Cobb","date":"December 30, 2020","format":false,"excerpt":"One of the great things about dbatool is that it allows you to run commands against multiple things. Sometimes you may need to run the same command on every server, or every database on a server, or every database on every server (not recommended). Today we're going to look at\u2026","rel":"","context":"In &quot;Configurations&quot;","block_context":{"text":"Configurations","link":"https:\/\/sqlnuggets.com\/category\/configurations\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2020\/12\/pexels-photo-97077.jpeg?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts\/1350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/comments?post=1350"}],"version-history":[{"count":22,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts\/1350\/revisions"}],"predecessor-version":[{"id":1376,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts\/1350\/revisions\/1376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/media\/1351"}],"wp:attachment":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/media?parent=1350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/categories?post=1350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/tags?post=1350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}