执行暂停Azure SQLDatawarehouse ps脚本时出错 [英] Error while executing Pause Azure SQLDatawarehouse ps script

查看:52
本文介绍了执行暂停Azure SQLDatawarehouse ps脚本时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行PowerShell Runbook时使用自动化帐户来暂停我的Azure Datawarehouse数据库.设置完成后,将创建凭据,拇指指纹证书.当我执行PS脚本并完成并显示错误消息

I am using Automation Account with execution of PowerShell Runbook for Pausing my Azure Datawarehouse database. Setup is completed with creation of crendentials, certificate for Thumbprints. When I executed the PS script and completed with error message

SQL Server上的SuspendOrPauseAzureSQLDataWarehouse上不存在名为ADWPOC的Azure SQL数据仓库:72个字符:72 + + CategoryInfo:未指定:(:) [Write-Error],WriteErrorException + FullyQualifiedErrorId:Microsoft.PowerShell.Commands.WriteErrorException

No Azure SQL Data Warehouse named ADWPOC exist on SQL Server At SuspendOrPauseAzureSQLDataWarehouse:72 char:72 + + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

在执行此脚本时,我已正确提供了数据库名称和服务器详细信息.我不确定这是什么问题.请指教.

I have provided the name of database and server details correctly while executing this script. I am not sure what is the problem here. Please advise.

我已经从运行手册库挂起或暂停Azure SQL数据仓库"中导入了PS脚本.请让我知道是否要在此处附加脚本?

I have imported the PS script from runbook gallery "Suspend Or Pause Azure SQL Data Warehouse". Please let me know if you want me to attach the script here?

推荐答案

不确定,但是脚本看起来太旧了,它仍然使用

Not sure, but the script looks too old, it still uses the AzureRm module which has been deprecated.

要在运行手册中暂停数据仓库,建议您使用新的

To pause the data warehouse in the runbook, I recommend you to use new Az module, sample here, to use that in runbook, just follow the steps as below.

1.在门户-> Modules 中导航到您的自动化帐户,确保已导入 Az.Accounts Az.Sql 模块(如果没有),请在 Modules -> Browse Gallery 中搜索模块并将其导入.

1.Navigate to your automation account in the portal -> Modules, make sure you have imported the Az.Accounts and Az.Sql modules, if not, in the Modules -> Browse Gallery, search for the modules and import them.

2.成功导入模块后,导航至 Runbooks ->创建一个 PowerShell Runbook(而不是 PowerShell Workflow ),然后在运行手册中使用以下脚本.

2.After importing the modules successfully, navigate to the Runbooks -> create a PowerShell runbook(not the PowerShell Workflow), then use the script as below in the runbook.

注意:<服务器名称> 应该类似于 testserver ,而不是 testserver.database.windows.net .

Note: The <server-name> should be like testserver, not 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."
}

这篇关于执行暂停Azure SQLDatawarehouse ps脚本时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆