0

When I'm trying to run the command New-AzureRmSqlDatabaseExport in an PowerShell Runbook it fails with the error message:

New-AzureRmSqlDatabaseExport : Object reference not set to an instance of an object.

I have verified that all modules are updated, AzureRM.Sql has version 4.12.1 when I'm writing this. New-AzureRmSqlDatabaseExport is a part of AzureRM.Sql and is also available in the runbook editor.

What I'm missing?

Update: The code I'm trying to run looks something like this:

$exportRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName "MyResourceGroup" -ServerName "MyServerName" -DatabaseName "MyDatabaseName" -StorageKeytype StorageAccessKey -StorageKey "MyStorageKey" -StorageUri "https://mystorage.blob.core.windows.net/backupdb/db.bacpac" -AdministratorLogin "userName" -AdministratorLoginPassword (ConvertTo-SecureString "mypassword" -AsPlainText -Force)

It does work Azure Cloud Shell.

PEK
  • 3,688
  • 2
  • 31
  • 49

1 Answers1

1

Before the command is executed, make sure that you are authenticated. Adding these lines before the command will solve this problem:

$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzureRmAccount -ServicePrincipal -Tenant $connection.TenantID `
-ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint

You find more information here:

https://learn.microsoft.com/en-us/azure/automation/automation-first-runbook-textual-powershell

PEK
  • 3,688
  • 2
  • 31
  • 49