不确定,但脚本看起来太旧了,它仍然使用AzureRm
已弃用的模块。
要在 Runbook 中暂停数据仓库,我建议您使用新Az
模块 ,sample here
要在 Runbook 中使用它,只需按照以下步骤操作即可。
1.在门户 -> 中导航到您的自动化帐户Modules
,确保您已导入Az.Accounts
和Az.Sql
模块,如果没有,请在Modules
->Browse Gallery
中搜索模块并导入它们。
2.成功导入模块后,导航到Runbooks
-> 创建PowerShell
运行手册(不是PowerShell Workflow
),然后在运行手册中使用如下脚本。
注意:<server-name>
应该是like testserver
,不是testserver.database.windows.net
。
$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
}
}
$database = Get-AzSqlDatabase –ResourceGroupName "<resource-group-name>" –ServerName "<server-name>" –DatabaseName "<data-warehouse-name>"
if($database){
if($database.Status -eq 'Paused'){
Write-Output "The Data Warehouse was already paused."
}else{
$database | Suspend-AzSqlDatabase
Write-Output "The Data Warehouse has been paused."
}
}else{
Write-Output "The Data Warehouse does not exist."
}