【问题标题】:Runbook automation fails but powershell cmd line works fineRunbook 自动化失败,但 powershell cmd 行工作正常
【发布时间】:2020-07-02 04:25:25
【问题描述】:

我有以下用于暂停 azure d/w 的 powershell 代码

$TenantId = "<>"
$SubscriptionId = "<>"


# Get the service principal credentials connected to the automation account. 
$SPCredential = Get-AutomationPSCredential -Name "psvar"

# Login to Azure ($null is to prevent output, since Out-Null doesn't work in Azure)
Write-Output "Login to Azure using automation account 'psvar'."
$null = Login-AzureRmAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -Credential $SPCredential

Write-Output "Login Status " 
# Select the correct subscription
Write-Output "Selecting subscription '$($SubscriptionId)'."
$null = Select-AzureRmSubscription -SubscriptionID $SubscriptionId

$ResourceGroupName = '<>'
$ServerName = '<>'
$DatabaseName = '<>'



Write-Output "Suspending $($DatabaseName)..."
$null = Suspend-AzureRmSqlDatabase `
        -ResourceGroupName $ResourceGroupName`
        -DatabaseName $DatabaseName`
        -ServerName $ServerName


Write-Output "Done"

暂停 azure rm sqldatabase 在 PowerShell Azure 命令行界面中运行良好 但是在运行手册自动化中它失败了

Suspend-AzureRmSqlDatabase : Run Login-AzureRmAccount to login.
At line:33 char:9
+ $null = Suspend-AzureRmSqlDatabase `
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Suspend-AzureRmSqlDatabase], PSInvalidOperationException
    + FullyQualifiedErrorId : 
InvalidOperation,Microsoft.Azure.Commands.Sql.DatabaseActivation.Cmdlet.SuspendAzureSqlDatabase

知道可能出了什么问题。感谢有关此的任何指示

【问题讨论】:

    标签: azure powershell automation


    【解决方案1】:

    我测试了您的脚本,它可以在运行手册中运行。

    导航到自动化帐户 -> Credentials,确保您的用户帐户名和密码正确。

    如果还是不行,你可以试试my solution here,它可以工作。

    【讨论】:

    • 谢谢,我的帐户是联合 AD a/c,所以它不起作用。
    • @Shiv 我在订阅的AAD租户中使用了一个工作账号,你也可以使用run as账号,参考我回复的最后一个链接。
    【解决方案2】:

    对于我们需要使用的 Azure Synapse 分析

    Update-AzSynapseSqlPool -WorkspaceName <wsname>-Name <dbname> -Pause 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      相关资源
      最近更新 更多