From 1c7a336d84c52bb4ecc9173e9f35b47b418bbbce Mon Sep 17 00:00:00 2001 From: Chris Gallagher Date: Mon, 28 Aug 2023 16:18:15 -0400 Subject: [PATCH] Fixes#200 change in syntax, easier to read/parse --- plugins/modules/database.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/modules/database.ps1 b/plugins/modules/database.ps1 index 46b78234..dc030946 100644 --- a/plugins/modules/database.ps1 +++ b/plugins/modules/database.ps1 @@ -63,15 +63,17 @@ try { if ($state -eq "absent") { if ($null -ne $existingDatabase) { - $droppedDatabase = ($existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false) - if ($droppedDatabase.Status -eq "Dropped") { - $module.Result.changed = $true - } - elseif ($droppedDatabase.Status -ne "Dropped") { - $module.FailJson("Drop database [$database] failed. " + $droppedDatabase.Status) + try { + $droppedDatabase = $existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false + if ($droppedDatabase.Status -eq "Dropped") { + $module.Result.changed = $true + } + elseif ($droppedDatabase.Status -ne "Dropped") { + $module.FailJson("Database [$database] was not dropped. " + $droppedDatabase.Status) + } } - else { - $module.FailJson("Drop database [$database] failed.", $_) + catch { + $module.FailJson("An exception occurred while trying to drop database [$database].", $_) } } $module.ExitJson()