sql - 我如何在 azure for DTU 上自动运行此脚本

标签 sql azure powershell azure-sql-database

 $ServiceObjective = Get-AzureSqlDatabaseServiceObjective -ServerName exampledb-ServiceObjectiveName S0
 Set-AzureSqlDatabase -DatabaseName exampledb-ServerName exampledb-ServiceObjective $ServiceObjective

我可以运行上面的脚本来使我的sql数据库S0 DTU级别,

我可以自动完成这个吗?

顺便说一句,我在论坛和 stackoverflow 上搜索过, 他们推荐自动化帐户和 rune 书。 但我没有 RunAsAccount。我没有管理员权限,无法创建 RunAsAccount。所以我无法使用 Runbook。

你能推荐我另一种方式吗?

谢谢:)

最佳答案

But i dont have RunAsAccount. I dont have admin privileges and i cant create RunAsAccount. So i couldnt use runbook.

如果您想创建具有运行方式帐户的自动化帐户,您需要在订阅中具有 Owner 角色,因为在创建运行方式帐户(服务主体)时,它会自动添加作为Contributor 订阅中的服务主体,只需使用Owner 即可完成。

但是,如果您只想在自动化帐户中使用 Runbook,则不需要 Owner 角色。您只需要求订阅中的所有者为您创建一个以帐户身份运行的自动化帐户,然后您就可以创建一个 powershell runbook 并使用以下命令运行上面的命令: 贡献者角色。

所有者为您创建自动化帐户后,请按照以下步骤操作。

1.导航到自动化帐户 -> Runbooks -> 创建 Runbook -> 创建 Powershell Runbook。

2.您使用的两个命令Get-AzureSqlDatabaseServiceObjectiveSet-AzureSqlDatabase属于Azure,即ASM powershell模块,它是旧的,如果要使用它们,则需要使用 Azure 经典运行方式帐户(CSP 订阅不支持)。因此我建议您使用新的 Az powershell 模块。在你的自动化账户->Modules中,检查Az.AccountsAz.Sql模块,如果没有,在模块 -> 浏览图库,搜索模块并导入它们。)

导入成功后,使用如下脚本登录并设置标准S0的sql数据库。

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Connect-AzAccount `
        -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-AzSqlDatabase -ResourceGroupName "<resource-group-name>" -DatabaseName "<database-name>" -ServerName "<server-name>" -Edition "Standard" -RequestedServiceObjectiveName "S0"

3.如果您想按计划自动运行脚本,可以点击此链接Scheduling a runbook in Azure Automation来做到这一点。

关于sql - 我如何在 azure for DTU 上自动运行此脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58503584/

相关文章:

azure - Azure 容器服务上的 Kubernetes

Azure数据湖: This request is not authorized to perform this operation

sql - 在单行中显示客户及其所有订单日期

sql - 如何将此查询转换为 SQL Server 2000 语法

MySQL错误: unknown table `airports`

powershell - 重启后自动登录

powershell - 为什么反转数组列表没有显示任何结果?

mysql - 在单个查询中从同一列不同的 WHERE 获得 2 个不同的结果

azure - 手动运行计划的 Azure WebJob

powershell - 在哪里可以找到二进制 DSC 资源的 dll?