0

我正在尝试在还原操作完成后缩减数据库并且遇到一些问题。我收到此异常,想知道 Azure 自动化工作流是否不支持此脚本中的某些内容?

无法使用指定的命名参数解析参数集。

workflow insertflowname
{
  <#  
  .SYNOPSIS   

本 Runbook 的目的是演示如何使用 Azure 自动化工作流将特定数据库还原到新数据库。然后将其缩减为基本。

.NOTES  

#>  


# Specify Azure Subscription Name

$subName = 'insertsubscription name'

# Connect to Azure Subscription
Connect-Azure -AzureConnectionName $subName
Select-AzureSubscription -SubscriptionName $subName

# Define source databasename
$SourceDatabaseName = 'insert database name'

# Define source server
$SourceServerName = 'insert source server'

# Define destination server
$TargetServerName = 'insert destination server'

Write-Output "`$SourceServerName [$SourceServerName]"
Write-Output "`$TargetServerName [$TargetServerName]"
Write-Output "`$SourceDatabaseName [$SourceDatabaseName]"

Write-Output "Retrieving recoverable database details for database [$SourceDatabaseName] on server [$SourceServerName]."
$RecoverableDatabase = Get-AzureSqlRecoverableDatabase –ServerName $SourceServerName -DatabaseName $SourceDatabaseName
$TargetDatabaseName = "$SourceDatabaseName-$($RecoverableDatabase.LastAvailableBackupDate.ToString('O'))"
Write-Output "`$TargetDatabaseName [$TargetDatabaseName]"

Write-Output "Starting recovery of database [$SourceDatabaseName] to server [$TargetServerName] as database [$TargetDatabaseName]."
Start-AzureSqlDatabaseRecovery -SourceDatabase $RecoverableDatabase -TargetServerName $TargetServerName –TargetDatabaseName $TargetDatabaseName 

$PollingInterval = 10
Write-Output "Monitoring status of recovery operation, polling every [$PollingInterval] second(s)."
$KeepGoing = $true
while ($KeepGoing) {
    $operation = Get-AzureSqlDatabaseOperation -ServerName $TargetServerName -DatabaseName $TargetDatabaseName | Where-Object {$_.Name -eq "DATABASE RECOVERY"} | Sort-Object StartTime -Descending
    if ($operation) {
        $operation[0]
        if ($operation[0].State -eq "COMPLETED") { $KeepGoing = $false }
        if ($operation[0].State -eq "FAILED") {
            # Throw error
            $KeepGoing = $false
        }
    } else {
        # Throw error since something went wrong and object was not created
        # May want to have this retry a few times before giving up or at least notify somebody
        # since at this point the recovery has been kicked off and you don't want the database
        # restore to remain at the elevated service level.
        $KeepGoing = $false
    }
    if ($KeepGoing) { Start-Sleep -Seconds $PollingInterval }
}

if ($operation[0].State -eq "COMPLETED") {
    Write-Output "Setting service level for database [$TargetDatabaseName] on server [$TargetServerName] to Basic."
    $ServiceObjective = Get-AzureSQLDatabaseServiceObjective –ServerName $TargetServerName –ServiceObjectiveName "Basic"
    $ServiceObjective
    Set-AzureSqlDatabase –ServerName $TargetServerName –DatabaseName $TargetDatabaseName –Edition "Basic" –ServiceObjective $ServiceObjective -MaxSizeGB 2 –Force
   }
}
4

1 回答 1

3

您可能遇到了此处描述的问题:https ://social.msdn.microsoft.com/Forums/en-US/ce6412b8-5cce-4573-befb-6017924ce0d0/whereobject-fails-with-parameter-set-cannot-be -resolved-using-the-specified-named-parameters?forum=azureautomation

摘要:在 PowerShell 工作流中使用参数名称,不要依赖位置参数。在这种情况下,您需要在 Where-Object 中添加 -FilterScript 参数名称。

于 2015-05-29T06:02:25.583 回答