0

When I run the runbook it appears the following message: Exception of type 'System.Exception' was thrown. The subscription name XXXX doesn't exist. Parameter name: name

It's just a simple script to get a backup of my mysql database and send to an storage account, nothing else....

I checked and the subscription name is the same as my automation account and also the database service i want to get the information




[CmdletBinding()]
param(
    [Parameter(Mandatory=$true)]
    [string]$DatabaseName
)

#$DatabaseName = 'xxxxxxxxxxxxxxxxxxx'
$storageAccountName = 'xxxxxxxxxxxxxxxxxxx'
$storageAccountKey='xxxxxxxxxxxxxxxxxxx'
$subscriptionName = 'xxxxxxxxxxxxxxxxxxx'
$databaseContainer = 'xxxxxxxxxxxxxxxxxxx'
$databaseServerName = 'xxxxxxxxxxxxxxxxxxx'
$databaseUserName = 'xxxxxxxxxxxxxxxxxxx'

$BlobName =  "${DatabaseName}_$(get-date -f yyyy-MM-dd).bacpac"

Write-Output "BlobName: $BlobName"

Import-AzurePublishSettingsFile '..\credentials\AzureManagementCredentials.publishsettings'
Set-AzureSubscription -SubscriptionName $subscriptionName
Select-AzureSubscription -SubscriptionName $subscriptionName


$databaseCredentials = Get-Credential `
                        -Message "Database Password Required" `
                        -UserName $databaseUserName

$storageContext = New-AzureStorageContext `
            –StorageAccountName $storageAccountName `
            -StorageAccountKey $storageAccountKey

$databaseContext = New-AzureSqlDatabaseServerContext `
                    -ServerName $databaseServerName `
                    -Credential $databaseCredentials

$exportRequest = Start-AzureSqlDatabaseExport `
            -SqlConnectionContext $databaseContext `
            -StorageContext $storageContext `
            -StorageContainerName $databaseContainer `
            -DatabaseName $DatabaseName `
            -BlobName $BlobName

do {

    Start-Sleep -s 60
    $status = Get-AzureSqlDatabaseImportExportStatus -Request $exportRequest

        Write-Output "Request Status: $($status.Status)"

     if($status.Status -eq "Failed")
        {
            Write-Output "Error message: $($status.ErrorMessage)"
            break
        }
}
while ($status.Status -ne 'Completed')

Read-Host "Done... Any key to exit"

  • Does this answer your question? [Azure PS Automation Provided subscription "xxxx" does not exists](https://stackoverflow.com/questions/51964853/azure-ps-automation-provided-subscription-xxxx-does-not-exists) – Ecstasy Aug 09 '22 at 05:38
  • [Azure powershell Select-AzureSubscription - error: the subscription name doesn't exist](https://stackoverflow.com/questions/34961993/azure-powershell-select-azuresubscription-error-the-subscription-name-doesnt) – Ecstasy Aug 09 '22 at 05:41

1 Answers1

0

One of the workaround you can follow to resolve the above issue,

Make sure that your current subscription is not part of the sandbox context or the Azure AD user of that subscription has configured as an administrator.

To disable the context by running follow cmdlts:-

Disable-AzContextAutosave -Scope Process

And then try to reconnect again , and select subscription using subscription ID instead of subscription name if still the issue persist.

For more information please refer this MICROSOFT DOCUMENTATION| Subscription name Not found, Import-AzurePublishSettingsFile and also aforementioned link by @deep as well.

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15