dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer

Home Page:https://dbatools.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Database Mail profiles do not allow adding more than one account

danielleshoemake opened this issue · comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

WARNING: [22:44:11][New-DbaDbMailProfile] Failure | Violation of UNIQUE KEY constraint
'SYSMAIL_PROFILE_NameMustBeUnique'. Cannot insert duplicate key in object 'dbo.sysmail_profile'. The duplicate key
value is (INGAA LLR Website Email Sender Profile).
The statement has been terminated.

Steps to Reproduce

New-DbaDbMailProfile -SqlInstance localhost -Profile "Test profile" -MailAccountName "Account 1" -MailAccountPriority 1
New-DbaDbMailProfile -SqlInstance localhost -Profile "Test profile" -MailAccountName "Account 2" -MailAccountPriority 2

Upon executing the second command, where the account name and priority has changed, a unique key constraint violation is issued. It seems that there is an attempt to recreate the entire profile versus checking if the profile already exists and then appending an account to the existing profile. It appears that creating the profile and adding an account to the profile are already two separate steps, but the fact that this is a one to many relationship is not accounted for.

Please confirm that you are running the most recent version of dbatools

2.1.3

Other details or mentions

Profiles can have multiple accounts, each is given a priority. The New-DbaDbMailProfile module configures priority, but it seems it only allows adding one account.

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.3770
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.3770
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

PSChildName Version


Client 4.8.03761
Full 4.8.03761
Client 4.0.0.0