Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Set-DbaAgentAlert] - Added ShouldProcess to the Rename to fix #8137 #8138

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions functions/Set-DbaAgentAlert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ function Set-DbaAgentAlert {
#region alert options
# Settings the options for the alert
if ($NewName) {
Write-Message -Message "Setting alert name to $NewName" -Level Verbose
$currentAlert.Rename($NewName)
if ($Pscmdlet.ShouldProcess($server, "Setting alert name to $NewName for $currentAlert")) {
$currentAlert.Rename($NewName)
}
}

if ($Enabled) {
Expand All @@ -149,9 +150,9 @@ function Set-DbaAgentAlert {
#endregion alert options

# Execute
if ($PSCmdlet.ShouldProcess($SqlInstance, "Changing the alert $a")) {
if ($PSCmdlet.ShouldProcess($SqlInstance, "Committing changes for alert $a")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Like in line 135, this should not be $a but $currentAlert.

try {
Write-Message -Message "Changing the alert" -Level Verbose
Write-Message -Message "Committing changes for alert $a" -Level Verbose
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this line, as ShouldProcess also has verbose output. (But if you still like to have the line: Like in line 135, this should not be $a but $currentAlert.)


# Change the alert
$currentAlert.Alter()
Expand Down