Remove-CosmosDatabase.ps1

function Remove-CosmosDatabase {
    <#
    .SYNOPSIS
    REmoves a Database
     
    .DESCRIPTION
    Removes a Database, all its Collections and all its Documents
     
    .PARAMETER DatabaseName
    Name of the Database you want to remove
     
    .PARAMETER CosmosDBVariables
    This is the Script variable generated by Connect-CosmosDB - no need to supply this variable, unless you get really creative
     
    .EXAMPLE
    Remove-CosmosDatabase -DatabaseName MyPrivateCosmos
     
    .NOTES
    https://docs.microsoft.com/en-us/rest/api/documentdb/delete-a-database
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,
        HelpMessage='Name of the database to remove')]
        [string]$DatabaseName,
        [Parameter(Mandatory=$false,
        HelpMessage="Use Connect-CosmosDB to create this Variable collection")]
        [hashtable]$CosmosDBVariables=$Script:CosmosDBVariables
    )
    
    begin {
        Test-CosmosDBVariable $CosmosDBVariables
    }
    
    process {
        $Database = $CosmosDBConnection[($DatabaseName + '_db')]
        if ($Database) {
            $Verb = 'DELETE'
            $Url = '{0}/{1}' -f $URI,$Database._self
            $ResourceType = 'dbs'
            $Header = New-CosmosDBHeader -resourceId $Database._rid -resourceType $ResourceType -Verb $Verb
            try {
                Invoke-RestMethod -Uri $Url -Headers $Header -Method $Verb -ErrorAction Stop
                $Script:CosmosDBConnection.Remove(($DatabaseName + '_db'))
                Write-Verbose "$DatabaseName has been removed"
            }
            catch {
                Write-Warning -Message $_.Exception.Message
            }
        } else {
            Write-Warning "$DatabaseName not found"
        }
    }
    
    end {
    }
}