Skip to content

Commit

Permalink
Testing for presence of operators on destination server
Browse files Browse the repository at this point in the history
  • Loading branch information
alevyinroc committed Feb 24, 2019
1 parent 5b387ff commit 8a8a8da
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions/Copy-DbaAgentAlert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ function Copy-DbaAgentAlert {
}
}

$destServerOperators = $destServer.JobServer.Operators.Name

foreach ($serverAlert in $serverAlerts) {
$alertName = $serverAlert.name
$copyAgentAlertStatus = [pscustomobject]@{
Expand All @@ -149,6 +151,12 @@ function Copy-DbaAgentAlert {
if (($Alert -and $Alert -notcontains $alertName) -or ($ExcludeAlert -and $ExcludeAlert -contains $alertName)) {
continue
}
$missingOperators = Compare-Object -ReferenceObject $serverAlert.Notifications.OperatorName -DifferenceObject $destServerOperators | where-object {$_.sideIndicator -eq "<="} | Select-Object -expandproperty InputObject

if ($null -ne $missingOperators) {
Write-Message "One or more operators alerted by $alertName is not present at the destination. Alert will not be copied. Use Copy-DbaAgentOperator to copy the operator(s) to the destination. Missing operator(s): $($missingOperators -join ',')"
continue
}

if ($destAlerts.name -contains $serverAlert.name) {
if ($force -eq $false) {
Expand Down

1 comment on commit 8a8a8da

@alevyinroc
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on fixing dataplat#4920

Please sign in to comment.