Skip to content
Permalink
Browse files

0.9.784

  • Loading branch information...
potatoqualitee committed Mar 11, 2019
1 parent e8f9dee commit 06b6f89cfd022374283ae7ae963204bffa244451
Showing with 276 additions and 5 deletions.
  1. +172 −4 allcommands.ps1
  2. +103 −0 bin/dbatools-index.json
  3. +1 −1 dbatools.psd1
[Alias('Silent')]
[switch]$EnableException
)

begin {
if (-not $script:isWindows) {
Stop-Function -Message "Copy-DbaPolicyManagement does not support Linux - we're still waiting for the Core SMOs from Microsoft"
$storePolicies = $null
}

<#
Categories
#>

Write-Message -Level Verbose -Message "Migrating categories"
$uniquePolicyCategories = $storePolicies | Select-Object -ExpandProperty PolicyCategory -Unique
$storeCategories = $sourceStore.PolicyCategories | Where-Object { $_.Name -in $uniquePolicyCategories }
foreach ($category in $storeCategories) {
$categoryName = $category.Name

$copyCategoryStatus = [pscustomobject]@{
SourceServer = $sourceServer.Name
DestinationServer = $destServer.Name
Name = $categoryName
Type = "Policy Category"
Status = $null
Notes = $null
DateTime = [DbaDateTime](Get-Date)
}

if ($null -ne $destStore.PolicyCategories['Database']) {
Write-Message -Level Verbose -Message "Policy category '$categoryName' was skipped because it already exists on $destination."

$copyCategoryStatus.Status = "Skipped"
$copyCategoryStatus.Notes = "Already exists on destination"
$copyCategoryStatus | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject
continue
}

if ($Pscmdlet.ShouldProcess($destination, "Migrating policy category $categoryName") -and $copyCategoryStatus.Status -ne 'Skipped') {
try {
$sql = $category.ScriptCreate().GetScript() | Out-String
Write-Message -Level Debug -Message $sql
Write-Message -Level Verbose -Message "Copying policy category $categoryName"
$null = $destServer.Query($sql)
$destStore.PolicyCategories.Refresh()

$copyCategoryStatus.Status = "Successful"
$copyCategoryStatus | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject
} catch {
$copyCategoryStatus.Status = "Failed"
$copyCategoryStatus.Notes = $_.Exception.Message
$copyCategoryStatus | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject

Stop-Function -Message "Issue creating policy category on $destination" -Target $categoryName -ErrorRecord $_
}
}
}

<#
Conditions
#>
#>

Write-Message -Level Verbose -Message "Migrating conditions"
foreach ($condition in $storeConditions) {

<#
Policies
#>
#>

Write-Message -Level Verbose -Message "Migrating policies"
foreach ($policy in $storePolicies) {
try {
$destStore.Conditions.Refresh()
$destStore.Policies.Refresh()
$sql = $policy.ScriptCreateWithDependencies().GetScript() | Out-String
$sql = $policy.ScriptCreate().GetScript() | Out-String
Write-Message -Level Debug -Message $sql
Write-Message -Level Verbose -Message "Copying policy $policyName"
$null = $destServer.Query($sql)
}
}
#ValidationTags#Messaging,FlowControl,Pipeline,CodeStyle#
function New-DbaDbMailAccount {
<#
.SYNOPSIS
Creates a new database mail account

.DESCRIPTION
Creates a new database mail account

.PARAMETER SqlInstance
The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2008 or higher.

.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Windows and SQL Authentication supported. Accepts credential objects (Get-Credential)

.PARAMETER Name
The Name of the account to be created.

.PARAMETER DisplayName
Sets the name of the mail account that is displayed in messages.

.PARAMETER Description
Sets the description of the purpose of the mail account.

.PARAMETER EmailAddress
Sets the e-mail address of the mail account.

.PARAMETER ReplyToAddress
Sets the e-mail address to which the mail account replies.

.PARAMETER MailServer
The name of the mail server.

.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

.PARAMETER Confirm
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

.NOTES
Tags: DbMail
Author: Chrissy LeMaire (@cl), netnerds.net

Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

.LINK
https://dbatools.io/New-DbaDbMailAccount

.EXAMPLE
PS C:\> $account = New-DbaDbMailAccount -SqlInstance sql2017 -Name 'The DBA Team' -EmailAddress admin@ad.local -MailServer smtp.ad.local

Creates a new db mail account with the email address admin@ad.local on sql2017 named "The DBA Team" using the smtp.ad.local mail server

#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = "Low")]
param (
[parameter(Mandatory, ValueFromPipeline)]
[Alias("ServerInstance", "SqlServer")]
[DbaInstanceParameter[]]$SqlInstance,
[PSCredential]$SqlCredential,
[parameter(Mandatory)]
[string]$Name,
[string]$DisplayName = $Name,
[string]$Description,
[parameter(Mandatory)]
[string]$EmailAddress,
[string]$ReplyToAddress,
[string]$MailServer,
[switch]$EnableException
)
process {
foreach ($instance in $SqlInstance) {
try {
$server = Connect-SqlInstance -SqlInstance $instance -SqlCredential $SqlCredential -MinimumVersion 11
} catch {
Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
}

if (Test-Bound -ParameterName MailServer) {
if (-not (Get-DbaDbMailServer -SqlInstance $server -Server $MailServer)) {
# Perhaps we should add a force to auto create the mail server
Stop-Function -Message "The mail server '$MailServer' does not exist on $instance" -ErrorRecord $_ -Target $instance -Continue
}
}

if ($Pscmdlet.ShouldProcess($instance, "Creating new db mail account called $Name")) {
try {
$account = New-Object Microsoft.SqlServer.Management.SMO.Mail.MailAccount $server.Mail, $Name
$account.DisplayName = $DisplayName
$account.Description = $Description
$account.EmailAddress = $EmailAddress
$account.ReplyToAddress = $ReplyToAddress
$account.Create()
} catch {
Stop-Function -Message "Failure creating db mail account" -Target $Name -ErrorRecord $_ -Continue
}

try {
$account.MailServers.Item($($server.DomainInstanceName)).Rename($MailServer)
$account.Alter()
$account.Refresh()
Add-Member -Force -InputObject $account -MemberType NoteProperty -Name ComputerName -value $server.ComputerName
Add-Member -Force -InputObject $account -MemberType NoteProperty -Name InstanceName -value $server.ServiceName
Add-Member -Force -InputObject $account -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName
$account | Select-DefaultView -Property ComputerName, InstanceName, SqlInstance, Id, Name, DisplayName, Description, EmailAddress, ReplyToAddress, IsBusyAccount, MailServers
} catch {
Stop-Function -Message "Failure returning output" -ErrorRecord $_ -Continue
}
}
}
}
}
#ValidationTags#Messaging,FlowControl,Pipeline,CodeStyle#
function New-DbaDbMailProfile {
<#
.SYNOPSIS
],
"Syntax": "New-DbaDbCertificate [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [[-Name] \u003cString[]\u003e] [[-Database] \u003cString[]\u003e] [[-Subject] \u003cString[]\u003e] [[-StartDate] \u003cDateTime\u003e] [[-ExpirationDate] \u003cDateTime\u003e] [-ActiveForServiceBrokerDialog] [[-SecurePassword] \u003cSecureString\u003e] [[-InputObject] \u003cDatabase[]\u003e] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
},
{
"Name": "New-DbaDbMailAccount",
"Description": "Creates a new database mail account",
"Tags": "DbMail",
"Synopsis": "Creates a new database mail account",
"Alias": "",
"Author": "Chrissy LeMaire (@cl), netnerds.net",
"CommandName": "New-DbaDbMailAccount",
"Availability": "Windows, Linux, macOS",
"Links": "https://dbatools.io/New-DbaDbMailAccount",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003e$account = New-DbaDbMailAccount -SqlInstance sql2017 -Name \u0027The DBA Team\u0027 -EmailAddress admin@ad.local -MailServer smtp.ad.local\nCreates a new db mail account with the email address admin@ad.local on sql2017 named \"The DBA Team\" using the smtp.ad.local mail server",
"Params": [
[
"SqlInstance",
"The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2008 or higher.",
"ServerInstance,SqlServer",
true,
"true (ByValue)",
""
],
[
"SqlCredential",
"Login to the target instance using alternative credentials. Windows and SQL Authentication supported. Accepts credential objects (Get-Credential)",
"",
false,
"false",
""
],
[
"Name",
"The Name of the account to be created.",
"",
true,
"false",
""
],
[
"DisplayName",
"Sets the name of the mail account that is displayed in messages.",
"",
false,
"false",
"$Name"
],
[
"Description",
"Sets the description of the purpose of the mail account.",
"",
false,
"false",
""
],
[
"EmailAddress",
"Sets the e-mail address of the mail account.",
"",
true,
"false",
""
],
[
"ReplyToAddress",
"Sets the e-mail address to which the mail account replies.",
"",
false,
"false",
""
],
[
"MailServer",
"The name of the mail server.",
"",
false,
"false",
""
],
[
"EnableException",
"By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.\r\nThis avoids overwhelming you with \"sea of red\" exceptions, but is inconvenient because it basically disables advanced scripting.\r\nUsing this switch turns this \"nice by default\" feature off and enables you to catch exceptions with your own try/catch.",
"",
false,
"false",
"False"
],
[
"WhatIf",
"If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.",
"wi",
false,
"false",
""
],
[
"Confirm",
"If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.",
"cf",
false,
"false",
""
]
],
"Syntax": "New-DbaDbMailAccount [-SqlInstance] \u003cDbaInstanceParameter[]\u003e [[-SqlCredential] \u003cPSCredential\u003e] [-Name] \u003cString\u003e [[-DisplayName] \u003cString\u003e] [[-Description] \u003cString\u003e] [-EmailAddress] \u003cString\u003e [[-ReplyToAddress] \u003cString\u003e] [[-MailServer] \u003cString\u003e] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
},
{
"Name": "New-DbaDbMailProfile",
"Description": "Creates a new database mail profile, and optionally associates it to a database mail account",
@@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.783'
ModuleVersion = '0.9.784'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'

0 comments on commit 06b6f89

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.