Database 自动化和重命名Azure数据库时出现问题

Database 自动化和重命名Azure数据库时出现问题,database,azure,automation,rename,Database,Azure,Automation,Rename,我正在尝试创建一个RunBook,用于重命名Azure DB以进行集成测试。我环顾了一下四周,这里有一些例子,但我仍然没有,我还没能让它们中的任何一个发挥作用。 我正在使用按量付费订阅,希望使用SQL登录 我认为获得正确的SQLServerContext是失败的,尽管我看不出我应该做些什么。我创建了只包含我的SQL用户名和SQL密码的自动化凭据 ` 编辑 为了让Joys脚本从当前设置运行,我必须添加以下步骤: 在automation中添加“运行方式帐户”(当前在automation的帐户设置下

我正在尝试创建一个RunBook,用于重命名Azure DB以进行集成测试。我环顾了一下四周,这里有一些例子,但我仍然没有,我还没能让它们中的任何一个发挥作用。 我正在使用按量付费订阅,希望使用SQL登录

我认为获得正确的SQLServerContext是失败的,尽管我看不出我应该做些什么。我创建了只包含我的SQL用户名和SQL密码的自动化凭据

`

编辑

为了让Joys脚本从当前设置运行,我必须添加以下步骤:

  • 在automation中添加“运行方式帐户”(当前在automation的帐户设置下的选项)
  • 将azure powershell模块更新为自动化模块部分下的最新更新
  • 确保我对db服务器使用了Azure名称,而不是SSMS名称(学童错误)
我正在尝试创建一个RunBook,用于重命名Azure DB以进行集成测试

如果这是您的最终目标,请尝试powershell runbook中的脚本,在我这方面效果很好

$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
    }
}

Set-AzureRmSqlDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -DatabaseName "joydb3" -NewName "joydb2"

你好,谢谢你的回复。我是Azure中的PS新手,发现似乎有3种连接风格:Azure、Azure Classic和ServicePrincipal。我没有Appid,所以我使用Add-AzureRmAccount-TenantId“xxxx”-SubscriptionId“xxxx”-Credential$Cred Set-AzureRmSqlDatabase-ResourceGroupName$RG-ServerName$svr-DatabaseName$DB1-NewName$DB2。我现在得到的错误是:Set-AzureRmSqlDatabase:找不到与参数名“NewName”匹配的参数。看看这些文件,我可以看到它就在那里。这是一个分层问题吗?我们正在使用basic@RichardH1.实际上,您应该有一个服务主体(如您所说的Appid),如果您创建一个自动化帐户,它将为您创建一个服务主体,并自动为订阅下的SP分配一个参与者角色。所以只要运行我的完整脚本。2.要解决此问题,请确保您已在自动化帐户中安装了
AzureRm
powershell模块,如果已安装,请尝试更新moudel,请参阅此。在创建Azure“运行方式帐户”之前,我无法更新模块,因此请尝试解决此问题。当必须创建应用程序时,我使用什么url。对于主页和标识URL,我注意安全问题…@RichardH,正如我所说的,如果你有一个自动化帐户,你不需要手动创建应用程序,只需尝试我的完整脚本。我无法帮助您在这里开始azure广告,这将是一个很长的对话,您需要自己检查文档。我已经取得了进展并创建了一个azure“运行方式帐户”,我现在的问题是-DatabaseName DB在点击Set-AzureRmSqlDatabase语句时找不到,我怀疑是因为它是SQL登录,而不是数据库上的windows。。。
$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
    }
}

Set-AzureRmSqlDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -DatabaseName "joydb3" -NewName "joydb2"