Below is the powershell script that you can use to backup the sql database to azure URL and I have commented accordingly in the script. Please make sure you have the credential created with name conventions like azurebackup simiarily and you also need have the storageuri to be updated correctly in the below script.
************************************************************************************
Powershell Script Started
**************************************************************************************
# 1. Prepare database name and Azure related Name
$ServerInstance = “******” ##Enter here the server instance name
$DatabaseName = “****” ## Provide your relevant Databasename
$extension= “BAK” ##extension for the backup file
$BackupFileName = “******” ##Provide the name of the backupfile that you want to be stored
$now = [datetime]::now.ToString(‘yyyy-MM-dd’) ## This is to get the timestamp for dynamic timestamp
Try {$ErrorActionPreference = ‘Stop’
# 2. Get Azure Storage Container Uri
$StorageUri =”https://xxxxxx.blob.core.windows.net:123/Storageaccount/Foldername” ## This you should have already if you use azure url account
$BackupUri = “$StorageUri/$BackupFileName.$now.$extension” ##Creating Dynamic timestamp for the backup files that being created with extension
# 3. Connect SqlServer cmdlet
Import-Module Sqlps -DisableNameChecking 3>$null#
#$test=”BACKUP DATABASE [$DatabaseName] TO URL=’$BackupUri’ WITH CREDENTIAL =’*****’,Compression;” ##Checking the syntax of the backup command thats being fired.
# 4. Start backup Main Script that executes the backup script
Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $DatabaseName -Query ” BACKUP DATABASE [$DatabaseName] TO URL=’$BackupUri’ WITH CREDENTIAL =’*****’,Compression;” -QueryTimeout 20000
Write-Host “Finished with Backup”} Catch { Throw} ## Main backup command that get executed when you run this powershell script.