It seems the Azure Run As Account no longer is working for any scripts. We've made no changes to it, the cert expires in 2018. This seems to be the cause but I do not have a solution to it.
Having trouble running Set-AzureRmSqlDatabase -ResourceGroupName "$RGName" -DatabaseName "$DBName" -ServerName "$ServerName" -Edition $Edition -ServiceObjective $DBLevel
as it generates this error:
Set-AzureRmSqlDatabase : Run Login-AzureRmAccount to login.
At line:56 char:1
+ Set-AzureRmSqlDatabase -ResourceGroupName "$RGName" -DatabaseName "$D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-AzureRmSqlDatabase], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Sql.Database.Cmdlet.SetAzureSqlDatabase
I thought the Add-AzureRmAccount
logs in the session. The other issue I've researched could be the values for the parameters. Sample values are:
$RGName: my-rg
$Edition: Standard
$ServerName: my-db-server
// not the fully qualified one but I tried it too
$DBName: my-db
$DBLevel: S0
The same top part works fine on another script to resize an application plan.
Code:
Param
(
[Parameter (Mandatory= $true)]
[String] $RGName,
[Parameter (Mandatory= $false)]
[String] $Edition="Standard",
[Parameter (Mandatory= $true)]
[String] $ServerName,
[Parameter (Mandatory= $true)]
[String] $DBName,
[Parameter (Mandatory= $true)]
[String] $DBLevel,
[Parameter (Mandatory= $false)]
[String] $SubId = "mysub"
)
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Select-AzureRmSubscription -SubscriptionId $SubId
Set-AzureRmSqlDatabase -ResourceGroupName "$RGName" -DatabaseName "$DBName" -ServerName "$ServerName" -Edition $Edition -RequestedServiceObjectiveName $DBLevel
You are not signed in into azure:
Set-AzureRmSqlDatabase : Run Login-AzureRmAccount to login
Logon and try again.
It seems you Add-AzureRmAccount fails. Remove the try catch and have a look at the return value.