gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:41:16 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com