functions/azure/Sql/Remove-BcAdminAzSqlDatabase.ps1
function Remove-BcAdminAzSqlDatabase { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$ResourceGroupName, [Parameter(Mandatory = $true)] [string]$ServerName, [Parameter(Mandatory = $true)] [string]$DatabaseName, [Parameter(Mandatory = $false)] [string]$ApiVersion = $BcAdminSession.AzureRestApiVersion, [switch]$Force ) if (-not (Connect-ToAzure)) { Write-Warning "Not connected to Microsoft Azure! Plase run Connect-ToAzure first!" return $false } $confirmation = Read-Host "Do you want to delete the database: $($DatabaseName)? This action cannot be undone! (y/n)" if ($confirmation -ne 'y') { Write-Warning "Delete database aborted by user!" return $false } $headers = @{ Authorization = $BcAdminSession.AzureRequestHeaderAuthorization } $uri = "https://management.azure.com/subscriptions/$($BcAdminSession.AzureSubscriptionId)/resourceGroups/$ResourceGroupName/providers/Microsoft.Sql/servers/$ServerName/databases/$($DatabaseName)?api-version=$ApiVersion" try { Write-Verbose "Delete database '$DatabaseName'." $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Delete Write-Verbose "Remove-BcAdminAzSqlDatabase response: $response" return $true } catch { if ($null -ne $_.Exception.Response) { try { $response = $_.ErrorDetails.Message | ConvertFrom-Json Write-Warning "$($response.error.code)`n$($response.error.Message)" return $false } catch { Write-Warning $_.Exception.Response return $false } } } } |