设置 AzureRmSqlDatabase 失败
Set-AzureRmSqlDatabase is failing
Azure 运行 As Account 似乎不再适用于任何脚本。我们没有对其进行任何更改,证书将在 2018 年到期。这似乎是原因,但我没有解决方案。
遇到问题 运行 Set-AzureRmSqlDatabase -ResourceGroupName "$RGName" -DatabaseName "$DBName" -ServerName "$ServerName" -Edition $Edition -ServiceObjective $DBLevel
因为它生成此错误:
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
我认为 Add-AzureRmAccount
登录会话。我研究过的另一个问题可能是参数值。样本值为:
$RGName: my-rg
$Edition: Standard
$ServerName: my-db-server
// 不是完全合格的,但我也试过了
$DBName: my-db
$DBLevel: S0
同样的顶部部分在另一个脚本上工作正常,以调整应用程序计划的大小。
代码:
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
您尚未登录 azure:
Set-AzureRmSqlDatabase : Run Login-AzureRmAccount to login
登录并重试。
您的 Add-AzureRmAccount 似乎失败了。删除 try catch 并查看 return 值。
Azure 运行 As Account 似乎不再适用于任何脚本。我们没有对其进行任何更改,证书将在 2018 年到期。这似乎是原因,但我没有解决方案。
遇到问题 运行 Set-AzureRmSqlDatabase -ResourceGroupName "$RGName" -DatabaseName "$DBName" -ServerName "$ServerName" -Edition $Edition -ServiceObjective $DBLevel
因为它生成此错误:
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
我认为 Add-AzureRmAccount
登录会话。我研究过的另一个问题可能是参数值。样本值为:
$RGName: my-rg
$Edition: Standard
$ServerName: my-db-server
// 不是完全合格的,但我也试过了
$DBName: my-db
$DBLevel: S0
同样的顶部部分在另一个脚本上工作正常,以调整应用程序计划的大小。
代码:
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
您尚未登录 azure:
Set-AzureRmSqlDatabase : Run Login-AzureRmAccount to login
登录并重试。
您的 Add-AzureRmAccount 似乎失败了。删除 try catch 并查看 return 值。